rerere.c: diagnose a corrupt MERGE_RR when hitting EOF between TAB and '\0'
[gitweb.git] / rerere.c
index d2608434750c336c3f3881efda8373b7c67d4b11..283a0024b05706b98e8056ac20258bf9248b80c7 100644 (file)
--- a/rerere.c
+++ b/rerere.c
@@ -42,8 +42,14 @@ static void read_rr(struct string_list *rr)
                name = xstrdup(buf);
                if (fgetc(in) != '\t')
                        die("corrupt MERGE_RR");
-               for (i = 0; i < sizeof(buf) && (buf[i] = fgetc(in)); i++)
-                       ; /* do nothing */
+               for (i = 0; i < sizeof(buf); i++) {
+                       int c = fgetc(in);
+                       if (c < 0)
+                               die("corrupt MERGE_RR");
+                       buf[i] = c;
+                       if (c == 0)
+                                break;
+               }
                if (i == sizeof(buf))
                        die("filename too long");
                string_list_insert(rr, buf)->util = name;