unpack_sha1_file: zero-pad the unpacked object.
authorLinus Torvalds <torvalds@ppc970.osdl.org>
Thu, 26 May 2005 01:25:08 +0000 (18:25 -0700)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Thu, 26 May 2005 01:25:08 +0000 (18:25 -0700)
This makes them easier to parse without having to worry about
running off the end, and allows us to treat commits as normal
strings.

sha1_file.c

index e6fdaa217a8ef7d2ac58e705d72bb7b34fd49282..ac7bf9fd271cd538e733d31332ab29cf36e4a69f 100644 (file)
@@ -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;
 }