]> git.kaiwu.me - haproxy.git/commitdiff
MEDIUM: tools: read_line_to_trash() handle empty files without \n
authorMia Kanashi <chad@redpilled.dev>
Wed, 6 May 2026 21:17:39 +0000 (00:17 +0300)
committerWilliam Lallemand <wlallemand@haproxy.com>
Thu, 7 May 2026 13:19:15 +0000 (15:19 +0200)
fgets() returns NULL when EOF is reached before newline, handle
that as a success for consistency, current behaviour is arguably a bug,
the API of fgets() is pretty weird after all so someone probably forgot.

src/tools.c

index 3adc7cf3f315940981b02630da8e9fab830459e4..268951629547da4871c9405c4b114a78933b713f 100644 (file)
@@ -6906,6 +6906,9 @@ ssize_t read_line_to_trash(const char *path_fmt, ...)
                        trash.data--;
                trash.area[trash.data] = 0;
                ret = trash.data; // success
+       } else if (feof(file)) {
+               /* empty file is allowed */
+               ret = 0;
        }
 
        fclose(file);