mirror of
https://github.com/neovim/neovim.git
synced 2025-12-13 18:12:50 +00:00
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:
committed by
github-actions[bot]
parent
8c311386c3
commit
3237f634fa
2
src/cjson/fpconv.c
vendored
2
src/cjson/fpconv.c
vendored
@@ -130,7 +130,7 @@ double fpconv_strtod(const char *nptr, char **endptr)
|
|||||||
/* Duplicate number into buffer */
|
/* Duplicate number into buffer */
|
||||||
if (buflen >= FPCONV_G_FMT_BUFSIZE) {
|
if (buflen >= FPCONV_G_FMT_BUFSIZE) {
|
||||||
/* Handle unusually large numbers */
|
/* Handle unusually large numbers */
|
||||||
buf = malloc(buflen + 1);
|
buf = (char *)malloc(buflen + 1);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
fprintf(stderr, "Out of memory");
|
fprintf(stderr, "Out of memory");
|
||||||
abort();
|
abort();
|
||||||
|
|||||||
7
src/cjson/strbuf.c
vendored
7
src/cjson/strbuf.c
vendored
@@ -39,7 +39,7 @@ static void die(const char *fmt, ...)
|
|||||||
va_end(arg);
|
va_end(arg);
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
|
|
||||||
exit(-1);
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
void strbuf_init(strbuf_t *s, size_t len)
|
void strbuf_init(strbuf_t *s, size_t len)
|
||||||
@@ -51,7 +51,7 @@ void strbuf_init(strbuf_t *s, size_t len)
|
|||||||
else
|
else
|
||||||
size = len + 1; /* \0 terminator */
|
size = len + 1; /* \0 terminator */
|
||||||
if (size < len)
|
if (size < len)
|
||||||
die("Overflow, len %zu", len);
|
die("Overflow, len: %zu", len);
|
||||||
s->buf = NULL;
|
s->buf = NULL;
|
||||||
s->size = size;
|
s->size = size;
|
||||||
s->length = 0;
|
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 */
|
/* Ensure there is room for optional NULL termination */
|
||||||
reqsize = len + 1;
|
reqsize = len + 1;
|
||||||
if (reqsize < len)
|
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 the user has requested to shrink the buffer, do it exactly */
|
||||||
if (s->size > reqsize)
|
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:
|
/* vi:ai et sw=4 ts=4:
|
||||||
*/
|
*/
|
||||||
|
|||||||
2
src/cjson/strbuf.h
vendored
2
src/cjson/strbuf.h
vendored
@@ -103,7 +103,7 @@ static inline char *strbuf_empty_ptr(strbuf_t *s)
|
|||||||
|
|
||||||
static inline void strbuf_set_length(strbuf_t *s, int len)
|
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)
|
static inline void strbuf_extend_length(strbuf_t *s, size_t len)
|
||||||
|
|||||||
Reference in New Issue
Block a user