diff options
author | Vicent Marti <tanoku@gmail.com> | 2014-11-21 13:31:30 +0100 |
---|---|---|
committer | Vicent Marti <tanoku@gmail.com> | 2014-11-21 17:21:33 +0100 |
commit | 92e0b67930f350a40575954f4638cbc71fee57d2 (patch) | |
tree | 5bd1f15f080785ee86f7c6fc4fca55d5336d6b0d | |
parent | 6f4461763eb0518112d22c3a096417e7eedf7385 (diff) | |
download | libgit2-92e0b67930f350a40575954f4638cbc71fee57d2.tar.gz |
buffer: Do not `put` anything if len is 0
-rw-r--r-- | src/buffer.c | 11 | ||||
-rw-r--r-- | tests/core/buffer.c | 5 |
2 files changed, 9 insertions, 7 deletions
diff --git a/src/buffer.c b/src/buffer.c index e9c420e16..7744d8f49 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -176,10 +176,13 @@ int git_buf_putcn(git_buf *buf, char c, size_t len) int git_buf_put(git_buf *buf, const char *data, size_t len) { - ENSURE_SIZE(buf, buf->size + len + 1); - memmove(buf->ptr + buf->size, data, len); - buf->size += len; - buf->ptr[buf->size] = '\0'; + if (len) { + assert(data); + ENSURE_SIZE(buf, buf->size + len + 1); + memmove(buf->ptr + buf->size, data, len); + buf->size += len; + buf->ptr[buf->size] = '\0'; + } return 0; } diff --git a/tests/core/buffer.c b/tests/core/buffer.c index 641fed630..87dec4607 100644 --- a/tests/core/buffer.c +++ b/tests/core/buffer.c @@ -281,11 +281,10 @@ check_buf_append_abc( /* more variations on append tests */ void test_core_buffer__5(void) { - check_buf_append("", "", "", 0, 8); - check_buf_append("a", "", "a", 1, 8); + check_buf_append("", "", "", 0, 0); + check_buf_append("a", "", "a", 1, 0); check_buf_append("", "a", "a", 1, 8); check_buf_append("", "a", "a", 1, 8); - check_buf_append("a", "", "a", 1, 8); check_buf_append("a", "b", "ab", 2, 8); check_buf_append("", "abcdefgh", "abcdefgh", 8, 16); check_buf_append("abcdefgh", "", "abcdefgh", 8, 16); |