Commit c1c399cf by Carlos Martín Nieto

config: handle EOF properly

In the main loop we peek to see what kind of line the next one is. If
there are multiple newlines before the end of the file, the eof marker
won't be set after we read the last line with data and we'll try to
peek again. This peek will return LF (as it pretends that we have a
newline at EOF so other function don't need any special handling).

Fix cfg_getchar so it doesn't try to read past the last character in
the file and config_parse so it considers LF as EOF on peek (as we're
ignoring spaces) and sets the reader's EOF flag to exit the parsing
loop.
parent 2866c016
......@@ -499,7 +499,8 @@ static int cfg_getchar(diskfile_backend *cfg_file, int flags)
assert(cfg_file->reader.read_ptr);
do c = cfg_getchar_raw(cfg_file);
while (skip_whitespace && isspace(c));
while (skip_whitespace && isspace(c) &&
!cfg_file->reader.eof);
if (skip_comments && (c == '#' || c == ';')) {
do c = cfg_getchar_raw(cfg_file);
......@@ -844,7 +845,8 @@ static int config_parse(diskfile_backend *cfg_file)
c = cfg_peek(cfg_file, SKIP_WHITESPACE);
switch (c) {
case '\0': /* We've arrived at the end of the file */
case '\n': /* EOF when peeking, set EOF in the reader to exit the loop */
cfg_file->reader.eof = 1;
break;
case '[': /* section header, new section begins */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment