Skip to content
Browse files

Fix color parsing code (prev. commit)

Also make sure there's enough parameters: Name, R, G and B
  • Loading branch information
sfan5 committed Oct 8, 2016
1 parent 173dd75 commit 0bf0d8e035b5b440c6c16c1bb295134d8d372d2c
Showing with 11 additions and 6 deletions.
  1. +11 −6 TileGenerator.cpp
@@ -261,24 +261,29 @@ void TileGenerator::generate(const std::string &input, const std::string &output

void TileGenerator::parseColorsStream(std::istream &in)
char line[128], *p;
char line[128];
while (in.good()) {
in.getline(line, 128);
while(*p++ != '\0') {

for(char *p = line; *p; p++) {
if(*p != '#')
*p = '\0'; // Cut off at the first #
if(strlen(line) == 0)

char name[64];
unsigned int r, g, b, a, t;
a = 255;
t = 0;

sscanf(line, "%64s %u %u %u %u %u", name, &r, &g, &b, &a, &t);
if(strlen(name) == 0)
int items = sscanf(line, "%64s %u %u %u %u %u", name, &r, &g, &b, &a, &t);
if(items < 4) {
std:cerr << "Failed to parse color entry '" << line << "'." << std::endl;

This comment has been minimized.

Copy link

Nestorfish Oct 8, 2016

Typo: std:cerr instead of std::cerr

This comment has been minimized.

Copy link

sfan5 Oct 9, 2016

Author Member

Why does this code compile though?

This comment has been minimized.

Copy link

Nestorfish Oct 9, 2016

"std" is interpreted as a label (for "goto" instruction for example) instead of a namespace for "cerr".
The " using namespace std" directive at the top of this file makes "std::" facultative and allows the code to compile, but could lead to name clashes.


ColorEntry color = ColorEntry(r, g, b, a, t);
m_colorMap[name] = color;

0 comments on commit 0bf0d8e

Please sign in to comment.
You can’t perform that action at this time.