diff --git a/src/zstream.c b/src/zstream.c index 82ae5e6f0..85fa2e0e6 100644 --- a/src/zstream.c +++ b/src/zstream.c @@ -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;