Resolve remaining feedback * replace some ints with size_ts * update NULL checks in various places
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
diff --git a/src/buffer.c b/src/buffer.c
index 50014fc..c56a755 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 5adc106..bf88a30 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);