Skip to content

Commit ad22d0a

Browse files
authored
fix(cjson): fix strbuf_set_length incorrectness neovim#35565
`strbuf_set_length` was incorrectly updating length with `+=` instead of assignment. Also syncs minor updates with upstream.
1 parent 0c49167 commit ad22d0a

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/cjson/fpconv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ double fpconv_strtod(const char *nptr, char **endptr)
130130
/* Duplicate number into buffer */
131131
if (buflen >= FPCONV_G_FMT_BUFSIZE) {
132132
/* Handle unusually large numbers */
133-
buf = malloc(buflen + 1);
133+
buf = (char *)malloc(buflen + 1);
134134
if (!buf) {
135135
fprintf(stderr, "Out of memory");
136136
abort();

src/cjson/strbuf.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static void die(const char *fmt, ...)
3939
va_end(arg);
4040
fprintf(stderr, "\n");
4141

42-
exit(-1);
42+
abort();
4343
}
4444

4545
void strbuf_init(strbuf_t *s, size_t len)
@@ -51,7 +51,7 @@ void strbuf_init(strbuf_t *s, size_t len)
5151
else
5252
size = len + 1; /* \0 terminator */
5353
if (size < len)
54-
die("Overflow, len %zu", len);
54+
die("Overflow, len: %zu", len);
5555
s->buf = NULL;
5656
s->size = size;
5757
s->length = 0;
@@ -132,7 +132,7 @@ static size_t calculate_new_size(strbuf_t *s, size_t len)
132132
/* Ensure there is room for optional NULL termination */
133133
reqsize = len + 1;
134134
if (reqsize < len)
135-
die("Overflow, len %zu", len);
135+
die("Overflow, len: %zu", len);
136136

137137
/* If the user has requested to shrink the buffer, do it exactly */
138138
if (s->size > reqsize)
@@ -194,5 +194,6 @@ void strbuf_append_string(strbuf_t *s, const char *str)
194194
}
195195
}
196196

197+
197198
/* vi:ai et sw=4 ts=4:
198199
*/

src/cjson/strbuf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static inline char *strbuf_empty_ptr(strbuf_t *s)
103103

104104
static inline void strbuf_set_length(strbuf_t *s, int len)
105105
{
106-
s->length += len;
106+
s->length = len;
107107
}
108108

109109
static inline void strbuf_extend_length(strbuf_t *s, size_t len)

0 commit comments

Comments
 (0)