diff options
author | Russell Belfer <rb@github.com> | 2014-01-30 10:23:35 -0800 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2014-01-30 10:23:35 -0800 |
commit | 19459b1e29e150c02e733bdefd5e1eb09fdd4bf7 (patch) | |
tree | 0465216ed6f457e977ef45caa3d90098c8278be7 /src/zstream.c | |
parent | 8606f33beadf5df48b36a64359c99d50aeb0f496 (diff) | |
download | libgit2-19459b1e29e150c02e733bdefd5e1eb09fdd4bf7.tar.gz |
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).
Diffstat (limited to 'src/zstream.c')
-rw-r--r-- | src/zstream.c | 7 |
1 files changed, 5 insertions, 2 deletions
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; |