Thread (1 message) 1 message, 1 author, 2016-06-15
DORMANTno replies

[PATCH 087/104] hash_object: correction for zero length file

From: Sam Vilain <hidden>
Date: 2016-06-15 22:48:51
Subsystem: the rest · Maintainer: Linus Torvalds

From: Dmitry Potapov <redacted>

The check whether size is zero was done after if size <= SMALL_FILE_SIZE,
as result, zero size case was never triggered. Instead zero length file
was treated as any other small file. This did not caused any problem, but
if we have a special case for size equal to zero, it is better to make it
work and avoid redundant malloc().

Signed-off-by: Dmitry Potapov <redacted>
Signed-off-by: Junio C Hamano <redacted>
---
 sha1_file.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/sha1_file.c b/sha1_file.c
index ff65328..1b551e4 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2448,6 +2448,8 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object,
 		else
 			ret = -1;
 		strbuf_release(&sbuf);
+	} else if (!size) {
+		ret = index_mem(sha1, NULL, size, write_object, type, path);
 	} else if (size <= SMALL_FILE_SIZE) {
 		char *buf = xmalloc(size);
 		if (size == read_in_full(fd, buf, size))
@@ -2456,12 +2458,11 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object,
 		else
 			ret = error("short read %s", strerror(errno));
 		free(buf);
-	} else if (size) {
+	} else {
 		void *buf = xmmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
 		ret = index_mem(sha1, buf, size, write_object, type, path);
 		munmap(buf, size);
-	} else
-		ret = index_mem(sha1, NULL, size, write_object, type, path);
+	}
 	close(fd);
 	return ret;
 }
-- 
1.7.1.rc2.333.gb2668
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help