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.

Can be backported to 3.0
---
 src/tools.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/tools.c b/src/tools.c
index 3adc7cf3f..268951629 100644
--- a/src/tools.c
+++ b/src/tools.c
@@ -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);
-- 
2.53.0


Reply via email to