Skip to content

Commit

Permalink
lib: fix infinite loop in __darr_in_vsprintf
Browse files Browse the repository at this point in the history
vsnprintf returns the number of bytes to write *not including* the
terminating NULL byte. When increasing the capacity of the array, we
should add one more byte, otherwise, if the error length is exactly a
power of 2, the capacity is not increased enough and vsnprintf always
fails.

Signed-off-by: Igor Ryzhov <[email protected]>
  • Loading branch information
idryzhov committed Mar 4, 2024
1 parent ee0c1cc commit 65567b5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/darr.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ char *__darr_in_vsprintf(char **sp, bool concat, const char *fmt, va_list ap)
else if ((size_t)len < darr_avail(*sp))
_darr_len(*sp) += len;
else {
darr_ensure_cap(*sp, darr_len(*sp) + (size_t)len);
darr_ensure_cap(*sp, darr_len(*sp) + (size_t)len + 1);
goto again;
}
return *sp;
Expand Down

0 comments on commit 65567b5

Please sign in to comment.