Skip to content

Commit

Permalink
Fixed staitc analyzer's 'nonnull' warning at the str_put_len function
Browse files Browse the repository at this point in the history
  • Loading branch information
proh14 committed Oct 8, 2024
1 parent b67e4cd commit e9cf993
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));
Expand Down

0 comments on commit e9cf993

Please sign in to comment.