From 82a19b6cae138bad3bd9930b3907d77fee9ae4f8 Mon Sep 17 00:00:00 2001 From: Christophe Le Roy Date: Sat, 8 Oct 2016 20:11:32 +0200 Subject: [PATCH] parseColorsStream: fix empty/white lines detection When input line is empty, sscanf does not write a '\0' to the %s target. Initialize its first byte to '\0' to properly detect empty lines after. Next, we do not want to stop reading the file upon reading an empty line: use continue instead of break. The latter was not noticed because of the former. --- TileGenerator.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/TileGenerator.cpp b/TileGenerator.cpp index 74f8fa2..da6c5ce 100644 --- a/TileGenerator.cpp +++ b/TileGenerator.cpp @@ -272,13 +272,14 @@ void TileGenerator::parseColorsStream(std::istream &in) } char name[64]; + name[0] = '\0'; 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; + continue; ColorEntry color = ColorEntry(r, g, b, a, t); m_colorMap[name] = color; }