fix(cjson): fix strbuf_set_length incorrectness #35565

`strbuf_set_length` was incorrectly updating
length with `+=` instead of assignment.

Also syncs minor updates with upstream.

(cherry picked from commit ad22d0ace9)
This commit is contained in:
skewb1k
2025-09-08 01:45:34 +03:00
committed by github-actions[bot]
parent 8c311386c3
commit 3237f634fa
3 changed files with 6 additions and 5 deletions

2
src/cjson/fpconv.c vendored
View File

@@ -130,7 +130,7 @@ double fpconv_strtod(const char *nptr, char **endptr)
/* Duplicate number into buffer */
if (buflen >= FPCONV_G_FMT_BUFSIZE) {
/* Handle unusually large numbers */
buf = malloc(buflen + 1);
buf = (char *)malloc(buflen + 1);
if (!buf) {
fprintf(stderr, "Out of memory");
abort();

7
src/cjson/strbuf.c vendored
View File

@@ -39,7 +39,7 @@ static void die(const char *fmt, ...)
va_end(arg);
fprintf(stderr, "\n");
exit(-1);
abort();
}
void strbuf_init(strbuf_t *s, size_t len)
@@ -51,7 +51,7 @@ void strbuf_init(strbuf_t *s, size_t len)
else
size = len + 1; /* \0 terminator */
if (size < len)
die("Overflow, len %zu", len);
die("Overflow, len: %zu", len);
s->buf = NULL;
s->size = size;
s->length = 0;
@@ -132,7 +132,7 @@ static size_t calculate_new_size(strbuf_t *s, size_t len)
/* Ensure there is room for optional NULL termination */
reqsize = len + 1;
if (reqsize < len)
die("Overflow, len %zu", len);
die("Overflow, len: %zu", len);
/* If the user has requested to shrink the buffer, do it exactly */
if (s->size > reqsize)
@@ -194,5 +194,6 @@ void strbuf_append_string(strbuf_t *s, const char *str)
}
}
/* vi:ai et sw=4 ts=4:
*/

2
src/cjson/strbuf.h vendored
View File

@@ -103,7 +103,7 @@ static inline char *strbuf_empty_ptr(strbuf_t *s)
static inline void strbuf_set_length(strbuf_t *s, int len)
{
s->length += len;
s->length = len;
}
static inline void strbuf_extend_length(strbuf_t *s, size_t len)