Skip to content

Commit

Permalink
fsck: do not abort upon finding an empty blob
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Sep 12, 2011
1 parent 509d597 commit eb726f2
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions builtin/fsck.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,9 @@ static void check_unreachable_object(struct object *obj)
unsigned long size;
char *buf = read_sha1_file(obj->sha1,
&type, &size);
if (buf) {
if (fwrite(buf, size, 1, f) != 1)
die_errno("Could not write '%s'",
filename);
free(buf);
}
if (buf && fwrite(buf, 1, size, f) != size)
die_errno("Could not write '%s'", filename);
free(buf);
} else
fprintf(f, "%s\n", sha1_to_hex(obj->sha1));
if (fclose(f))
Expand Down

0 comments on commit eb726f2

Please sign in to comment.