Skip to content

Commit

Permalink
🐛 Removed warnings about empty lines in config
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ohlidalp authored and AnotherFoxGuy committed Dec 20, 2017
1 parent a26ea2b commit 6a57318
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions source/common/UnicodeStrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 4 additions & 0 deletions source/server/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 6a57318

Please sign in to comment.