Skip to content

Commit

Permalink
Merge pull request #537 from stoeckmann/vsnprintf
Browse files Browse the repository at this point in the history
Handle vsnprintf corner cases.
  • Loading branch information
akheron committed May 23, 2020
2 parents e9ebfa7 + 38b001e commit 52dfc3d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/value.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,16 +797,18 @@ json_t *json_vsprintf(const char *fmt, va_list ap) {
va_copy(aq, ap);

length = vsnprintf(NULL, 0, fmt, ap);
if (length < 0)
goto out;
if (length == 0) {
json = json_string("");
goto out;
}

buf = jsonp_malloc(length + 1);
buf = jsonp_malloc((size_t)length + 1);
if (!buf)
goto out;

vsnprintf(buf, length + 1, fmt, aq);
vsnprintf(buf, (size_t)length + 1, fmt, aq);
if (!utf8_check_string(buf, length)) {
jsonp_free(buf);
goto out;
Expand Down

0 comments on commit 52dfc3d

Please sign in to comment.