From e9cf993d4e08c24d9052aec21e8eb0f0c85cebf4 Mon Sep 17 00:00:00 2001 From: Hoorad Farrokh Date: Wed, 9 Oct 2024 08:56:33 +1300 Subject: [PATCH] Fixed staitc analyzer's 'nonnull' warning at the str_put_len function --- util.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/util.c b/util.c index 56d8a3f..36b9e3d 100644 --- a/util.c +++ b/util.c @@ -532,9 +532,9 @@ void str_sprintf(str_t *str, const char *fmt, ...) { void str_put_len(str_t *str, char *data, size_t data_len, int is_prepend) { size_t req_cap; req_cap = str->len + data_len + 1; - if (req_cap > str->cap) { - str_ensure_cap(str, req_cap); - } + + str_ensure_cap(str, req_cap); + if (is_prepend) { memmove(str->data + data_len, str->data, str->len); memcpy(str->data, data, data_len); @@ -547,7 +547,7 @@ void str_put_len(str_t *str, char *data, size_t data_len, int is_prepend) { // Ensure space in str void str_ensure_cap(str_t *str, size_t cap) { - if (cap > str->cap) { + if (!str->data || cap > str->cap) { if (str->inc >= 0) { // If inc is positive, grow linearly cap = MLBUF_MAX(cap, str->cap + (str->inc > 0 ? str->inc : 128));