summaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-05-26 01:25:08 (GMT)
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-05-26 01:25:08 (GMT)
commite871b649a3f4ede26eb98c7d46df7acdc7ecbe81 (patch)
tree47039eefa22fcbbe31884cac4fe0ab067f795105 /sha1_file.c
parent9fdade06739af0b3e27422a973ae4fd83e3c918e (diff)
downloadgit-e871b649a3f4ede26eb98c7d46df7acdc7ecbe81.zip
git-e871b649a3f4ede26eb98c7d46df7acdc7ecbe81.tar.gz
git-e871b649a3f4ede26eb98c7d46df7acdc7ecbe81.tar.bz2
unpack_sha1_file: zero-pad the unpacked object.
This makes them easier to parse without having to worry about running off the end, and allows us to treat commits as normal strings.
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/sha1_file.c b/sha1_file.c
index e6fdaa2..ac7bf9f 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -329,7 +329,7 @@ void * unpack_sha1_file(void *map, unsigned long mapsize, char *type, unsigned l
return NULL;
bytes = strlen(buffer) + 1;
- buf = xmalloc(*size);
+ buf = xmalloc(1+*size);
memcpy(buf, buffer + bytes, stream.total_out - bytes);
bytes = stream.total_out - bytes;
@@ -339,6 +339,7 @@ void * unpack_sha1_file(void *map, unsigned long mapsize, char *type, unsigned l
while (inflate(&stream, Z_FINISH) == Z_OK)
/* nothing */;
}
+ buf[*size] = 0;
inflateEnd(&stream);
return buf;
}