From 8293d2ef9165d7f7f30c9dd877a3cb9a25a976f7 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 25 Jul 2026 12:23:25 -1000 Subject: Skip a malformed config line --- source/configfile.c | 58 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/source/configfile.c b/source/configfile.c index aa6c4fa..9bf2da1 100644 --- a/source/configfile.c +++ b/source/configfile.c @@ -32,38 +32,48 @@ static void skip_line(FILE *f) static int read_config_line(FILE *f, struct strbuf *name, struct strbuf *value) { - int c = next_char(f); + int c; - strbuf_reset(name); strbuf_reset(value); - /* Skip comments and preceding spaces. */ - for(;;) { - if (c == EOF) - return 0; - else if (c == '#' || c == ';') - skip_line(f); - else if (!isspace(c)) - break; + for (;;) { c = next_char(f); - } - /* Read variable name. */ - while (c != '=') { - if (c == '\n' || c == EOF) - return 0; - strbuf_addch(name, c); - c = next_char(f); - } + // Skip comments and preceding spaces. + for (;;) { + if (c == EOF) + return 0; + else if (c == '#' || c == ';') + skip_line(f); + else if (!isspace(c)) + break; + c = next_char(f); + } - /* Read variable value. */ - c = next_char(f); - while (c != '\n' && c != EOF) { - strbuf_addch(value, c); + // Read variable name. + strbuf_reset(name); + while (c != '=') { + if (c == EOF) + return 0; + // A line without '=' is malformed. Skip it and keep + // reading so a typo does not drop the rest of the file. + if (c == '\n') + break; + strbuf_addch(name, c); + c = next_char(f); + } + if (c != '=') + continue; + + // Read variable value. c = next_char(f); - } + while (c != '\n' && c != EOF) { + strbuf_addch(value, c); + c = next_char(f); + } - return 1; + return 1; + } } int parse_configfile(const char *filename, configfile_value_fn fn) -- cgit v2.8.0