diff options
-rw-r--r-- | src/buffer.c | 28 | ||||
-rw-r--r-- | tests-clay/core/buffer.c | 8 |
2 files changed, 15 insertions, 21 deletions
diff --git a/src/buffer.c b/src/buffer.c index 50014fc11..c56a75598 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -79,8 +79,8 @@ void git_buf_put(git_buf *buf, const char *data, size_t len) void git_buf_puts(git_buf *buf, const char *string) { - if (string != NULL) - git_buf_put(buf, string, strlen(string)); + assert(string); + git_buf_put(buf, string, strlen(string)); } void git_buf_printf(git_buf *buf, const char *format, ...) @@ -121,12 +121,10 @@ const char *git_buf_cstr(git_buf *buf) void git_buf_free(git_buf *buf) { - assert(buf); + if (!buf) return; - if (buf->ptr) { - git__free(buf->ptr); - buf->ptr = NULL; - } + git__free(buf->ptr); + buf->ptr = NULL; buf->asize = 0; buf->size = 0; } @@ -179,7 +177,7 @@ void git_buf_join_n(git_buf *buf, char separator, int nbuf, ...) va_list ap; int i; - int total_size = 0; + size_t total_size = 0; char *out; if (buf->size > 0 && buf->ptr[buf->size - 1] != separator) @@ -188,7 +186,7 @@ void git_buf_join_n(git_buf *buf, char separator, int nbuf, ...) va_start(ap, nbuf); for (i = 0; i < nbuf; ++i) { const char* segment; - int segment_len; + size_t segment_len; segment = va_arg(ap, const char *); if (!segment) @@ -212,7 +210,7 @@ void git_buf_join_n(git_buf *buf, char separator, int nbuf, ...) va_start(ap, nbuf); for (i = 0; i < nbuf; ++i) { const char* segment; - int segment_len; + size_t segment_len; segment = va_arg(ap, const char *); if (!segment) @@ -245,11 +243,11 @@ void git_buf_join( const char *str_a, const char *str_b) { - int add_size = 0; - int sep_a = 0; - int strlen_a = 0; - int sep_b = 0; - int strlen_b = 0; + size_t add_size = 0; + size_t sep_a = 0; + size_t strlen_a = 0; + size_t sep_b = 0; + size_t strlen_b = 0; char *ptr; /* calculate string lengths and need for added separators */ diff --git a/tests-clay/core/buffer.c b/tests-clay/core/buffer.c index 5adc106dd..bf88a3073 100644 --- a/tests-clay/core/buffer.c +++ b/tests-clay/core/buffer.c @@ -257,12 +257,9 @@ check_buf_append_abc( /* more variations on append tests */ void test_core_buffer__5(void) { - check_buf_append(NULL, NULL, NULL, 0, 0); - check_buf_append(NULL, "", "", 0, 8); - check_buf_append("", NULL, "", 0, 8); check_buf_append("", "", "", 0, 8); - check_buf_append("a", NULL, "a", 1, 8); - check_buf_append(NULL, "a", "a", 1, 8); + 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", "", "a", 1, 8); check_buf_append("a", "b", "ab", 2, 8); @@ -287,7 +284,6 @@ void test_core_buffer__5(void) check_buf_append(REP16("x"), REP16("o"), REP16("x") REP16("o"), 32, 40); - check_buf_append(test_4096, NULL, test_4096, 4096, 6144); check_buf_append(test_4096, "", test_4096, 4096, 6144); check_buf_append(test_4096, test_4096, test_8192, 8192, 9216); |