mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-09 20:29:27 +00:00
Defer zstream NUL termination to end
And don't terminate if there isn't space for it (since it's binary data, it's not worth a reallocation).
This commit is contained in:
parent
8606f33bea
commit
19459b1e29
@ -134,7 +134,7 @@ int git_zstream_deflatebuf(git_buf *out, const void *in, size_t in_len)
|
||||
while (!git_zstream_done(&zs)) {
|
||||
size_t step = git_zstream_suggest_output_len(&zs), written;
|
||||
|
||||
if ((error = git_buf_grow(out, out->asize + step + 1)) < 0)
|
||||
if ((error = git_buf_grow(out, out->asize + step)) < 0)
|
||||
goto done;
|
||||
|
||||
written = out->asize - out->size;
|
||||
@ -144,9 +144,12 @@ int git_zstream_deflatebuf(git_buf *out, const void *in, size_t in_len)
|
||||
goto done;
|
||||
|
||||
out->size += written;
|
||||
out->ptr[out->size] = '\0';
|
||||
}
|
||||
|
||||
/* NULL terminate for consistency if possible */
|
||||
if (out->size < out->asize)
|
||||
out->ptr[out->size] = '\0';
|
||||
|
||||
done:
|
||||
git_zstream_free(&zs);
|
||||
return error;
|
||||
|
Loading…
Reference in New Issue
Block a user