From: Daniel Stenberg Date: Fri, 7 Mar 2025 11:11:31 +0000 (+0100) Subject: tool_parsecfg: make my_get_line() skip empty and blanks-only lines X-Git-Tag: curl-8_13_0~219 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=906aa04d9be6c5579356161bbb92df1db9a299e1;p=thirdparty%2Fcurl.git tool_parsecfg: make my_get_line() skip empty and blanks-only lines Closes #16613 --- diff --git a/src/tool_parsecfg.c b/src/tool_parsecfg.c index a462b4322c..6f07423e03 100644 --- a/src/tool_parsecfg.c +++ b/src/tool_parsecfg.c @@ -304,7 +304,8 @@ static bool get_line(FILE *input, struct dynbuf *buf, bool *error) else if(b[rlen-1] == '\n') { /* end of the line, drop the newline */ size_t len = curlx_dyn_len(buf); - curlx_dyn_setlen(buf, len - 1); + if(len) + curlx_dyn_setlen(buf, len - 1); return TRUE; /* all good */ } @@ -327,15 +328,18 @@ bool my_get_line(FILE *input, struct dynbuf *buf, bool *error) do { retcode = get_line(input, buf, error); if(!*error && retcode) { - const char *line = curlx_dyn_ptr(buf); - if(line) { + size_t len = curlx_dyn_len(buf); + if(len) { + const char *line = curlx_dyn_ptr(buf); while(ISBLANK(*line)) line++; /* a line with # in the first non-blank column is a comment! */ - if((*line == '#') || (*line == '\n')) + if((*line == '#') || !*line) continue; } + else + continue; /* avoid returning an empty line */ } break; } while(retcode);