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.
This commit is contained in:
Linus Torvalds 2005-05-25 18:25:08 -07:00
Родитель 9fdade0673
Коммит e871b649a3
1 изменённых файлов: 2 добавлений и 1 удалений

Просмотреть файл

@ -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;
}