Commit 19459b1e by Russell Belfer

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).
parent 8606f33b
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment