]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tool_parsecfg: make my_get_line() skip empty and blanks-only lines
authorDaniel Stenberg <daniel@haxx.se>
Fri, 7 Mar 2025 11:11:31 +0000 (12:11 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 7 Mar 2025 22:34:36 +0000 (23:34 +0100)
Closes #16613

src/tool_parsecfg.c

index a462b4322cc793a911270691a0428fdc36c7af9d..6f07423e03577f4290ddb98e6fae49d4eba3a7f0 100644 (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);