From 0bf0d8e035b5b440c6c16c1bb295134d8d372d2c Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 8 Oct 2016 21:58:56 +0200 Subject: [PATCH] Fix color parsing code (prev. commit) Also make sure there's enough parameters: Name, R, G and B --- TileGenerator.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/TileGenerator.cpp b/TileGenerator.cpp index cb33d71..5e711fc 100644 --- a/TileGenerator.cpp +++ b/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 != '#') continue; *p = '\0'; // Cut off at the first # break; } + if(strlen(line) == 0) + continue; 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) - break; + 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; + continue; + } + ColorEntry color = ColorEntry(r, g, b, a, t); m_colorMap[name] = color; }