Re: [PATCH] Support empty blob in fsck --lost-found

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH] Support empty blob in fsck --lost-found

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:52:01

BJ Hargrave [off-list ref] writes:
quoted hunk
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 5ae0366..ad6d713 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -232,9 +232,10 @@ static void check_unreachable_object(struct object *obj)
 				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);
+					if (size > 0)
+						if (fwrite(buf, size, 1, f) != 1)
+							die_errno("Could not write '%s'",
+								  filename);
Funny.

I am sure we fixed a similar breakage elsewhere a few years ago, by
swapping the size and nmemb to the calls (i.e. instead of writing one
block of "size" bytes, you could write "size" blocks of 1-byte) and making
sure fwrite() reports the number of items. IOW

	if (buf && fwrite(buf, 1, size, f) != size)
		die_errno("Could not write '%s'", filename);

Re: [PATCH] Support empty blob in fsck --lost-found

From: BJ Hargrave <hidden>
Date: 2016-06-15 22:52:01

On Sep 11, 2011, at 16:43 , Junio C Hamano wrote:
Funny.

I am sure we fixed a similar breakage elsewhere a few years ago, by
swapping the size and nmemb to the calls (i.e. instead of writing one
block of "size" bytes, you could write "size" blocks of 1-byte) and making
sure fwrite() reports the number of items. IOW

	if (buf && fwrite(buf, 1, size, f) != size)
		die_errno("Could not write '%s'", filename);
Do you want me to resubmit the patch using this technique instead of the size > 0 check?
-- 

BJ
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help