tool_parsecfg: make my_get_line() skip empty and blanks-only lines

Closes #16613
This commit is contained in:
Daniel Stenberg 2025-03-07 12:11:31 +01:00
parent 36a831b868
commit 906aa04d9b
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -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);