fix(cid/352782): assert str->items is non-NULL to hint static analyzers

The earlier vsnprintf() call checks whether str->items is NULL, sets of
the "possible NULL" spidey sense.  kv_ensure_space() guarantees
str->items is non-NULL but since it doesn't use NULL checks to decide
whether to alloc, static analyzers can't tell this code path is safe.
This commit is contained in:
James McCoy 2022-05-20 06:58:42 -04:00
parent d31e68d5d0
commit 501ee06d3a
No known key found for this signature in database
GPG Key ID: DFE691AE331BA3DB

View File

@ -1496,6 +1496,7 @@ int kv_do_printf(StringBuilder *str, const char *fmt, ...)
// printed string didn't fit, resize and try again // printed string didn't fit, resize and try again
if ((size_t)printed >= remaining) { if ((size_t)printed >= remaining) {
kv_ensure_space(*str, (size_t)printed + 1); // include space for NUL terminator at the end kv_ensure_space(*str, (size_t)printed + 1); // include space for NUL terminator at the end
assert(str->items != NULL);
va_start(ap, fmt); va_start(ap, fmt);
printed = vsnprintf(str->items + str->size, str->capacity - str->size, fmt, ap); printed = vsnprintf(str->items + str->size, str->capacity - str->size, fmt, ap);
va_end(ap); va_end(ap);