summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 509d597)
raw | patch | inline | side by side (parent: 509d597)
author | Junio C Hamano <gitster@pobox.com> | |
Mon, 12 Sep 2011 01:03:38 +0000 (18:03 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 12 Sep 2011 01:03:38 +0000 (18:03 -0700) |
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>
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>
builtin/fsck.c | patch | blob | history |
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 5ae0366bc8cfe52f226c2af151a66d39b9df02aa..df1a88b51ae7773a15276d144113c0002fddb1cd 100644 (file)
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
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))