From 6a573188d2c288256f644ac5dfaad708bf92ce69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Ohl=C3=ADdal?= Date: Wed, 20 Dec 2017 11:43:52 +0100 Subject: [PATCH] :bug: Removed warnings about empty lines in config This required fixing a bug in 'Str::TrimAscii()' function - if the line contained only whitespace, the 'past the end' pointer ended up before the 'start' pointer. Fixes #48 --- source/common/UnicodeStrings.h | 6 +++--- source/server/config.cpp | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/source/common/UnicodeStrings.h b/source/common/UnicodeStrings.h index ba802810..70c99d11 100644 --- a/source/common/UnicodeStrings.h +++ b/source/common/UnicodeStrings.h @@ -153,13 +153,13 @@ namespace Str { } // TODO: implement `TrimUtf8()`! -/// @param start Pointer to first character -/// @param end Pointer to after-the-last character +/// @param start Pointer to first character (or NUL-terminating character if the string is empty) +/// @param end Pointer to after-the-last character (the NUL-terminating character) inline void TrimAscii(char *&start, char *&end) { while ((start != end) && IsWhitespaceAscii(*start)) ++start; - while ((start != (end - 1)) && IsWhitespaceAscii(*(end - 1))) + while ((start != end) && IsWhitespaceAscii(*(end - 1))) --end; } diff --git a/source/server/config.cpp b/source/server/config.cpp index c01ad923..8e63fcd8 100644 --- a/source/server/config.cpp +++ b/source/server/config.cpp @@ -519,6 +519,10 @@ namespace Config { char *key_start = line_buf; char *val_end = line_buf + strlen(line_buf); Str::TrimAscii(key_start, val_end); // In-out + + if (key_start == val_end) + continue; // Skip empty lines + if (*key_start == '#') continue; // Skip comment lines