Don't access line[-1] for a zero-length "line" from fgets.
[git/git.git] / builtin-pack-objects.c
index e0ce114..a39cb82 100644 (file)
@@ -2013,7 +2013,7 @@ static void get_object_list(int ac, const char **av)
 
        while (fgets(line, sizeof(line), stdin) != NULL) {
                int len = strlen(line);
-               if (line[len - 1] == '\n')
+               if (len && line[len - 1] == '\n')
                        line[--len] = 0;
                if (!len)
                        break;