Commit 92e0b679 by Vicent Marti

buffer: Do not `put` anything if len is 0

parent 6f446176
......@@ -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)
{
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;
}
......
......@@ -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);
......
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