Skip to content

Commit

Permalink
Merge pull request #15470 from idryzhov/fix-darr-vsprintf
Browse files Browse the repository at this point in the history
lib: fix __darr_in_vsprintf
  • Loading branch information
choppsv1 authored Mar 5, 2024
2 parents c256a9a + cb6032d commit 21aa863
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/darr.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ char *__darr_in_vsprintf(char **sp, bool concat, const char *fmt, va_list ap)
size_t inlen = concat ? darr_strlen(*sp) : 0;
size_t capcount = strlen(fmt) + MIN(inlen + 64, 128);
ssize_t len;
va_list ap_copy;

darr_ensure_cap(*sp, capcount);

Expand All @@ -68,10 +69,12 @@ char *__darr_in_vsprintf(char **sp, bool concat, const char *fmt, va_list ap)
if (darr_len(*sp) == 0)
*darr_append(*sp) = 0;
again:
len = vsnprintf(darr_last(*sp), darr_avail(*sp), fmt, ap);
va_copy(ap_copy, ap);
len = vsnprintf(darr_last(*sp), darr_avail(*sp) + 1, fmt, ap_copy);
va_end(ap_copy);
if (len < 0)
darr_in_strcat(*sp, fmt);
else if ((size_t)len < darr_avail(*sp))
else if ((size_t)len <= darr_avail(*sp))
_darr_len(*sp) += len;
else {
darr_ensure_cap(*sp, darr_len(*sp) + (size_t)len);
Expand Down

0 comments on commit 21aa863

Please sign in to comment.