fsck: do not abort upon finding an empty blob

Asking fwrite() to write one item of size bytes results in fwrite() reporting "I wrote zero item", when size is zero. Instead, we could ask it to write "size" items of 1 byte and expect it to report that "I wrote size items" when it succeeds, with any value of size, including zero. Noticed and reported by BJ Hargrave. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Sep 11, 2011 at 18:03 UTC eb726f2d760dd78915e4a24f014ab411a165daa3
1 file changed +3 -6
builtin/fsck.c
+3 -6
@@ -231,12 +231,9 @@ static void check_unreachable_object(struct object *obj)
231 unsigned long size;
232 char *buf = read_sha1_file(obj->sha1,
233 &type, &size);
234 - if (buf) {
235 - if (fwrite(buf, size, 1, f) != 1)
236 - die_errno("Could not write '%s'",
237 - filename);
238 - free(buf);
239 - }
234 + if (buf && fwrite(buf, 1, size, f) != size)
235 + die_errno("Could not write '%s'", filename);
236 + free(buf);
237 } else
238 fprintf(f, "%s\n", sha1_to_hex(obj->sha1));
239 if (fclose(f))