Skip to content

Commit ab2cfa9

Browse files
waahm7TingDaoK
andauthored
Update CJson to v1.7.18 (#1116)
Co-authored-by: Dengke Tang <[email protected]>
1 parent 6ebf3bc commit ab2cfa9

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ jobs:
125125
python builder.pyz build -p ${{ env.PACKAGE_NAME }} --target windows-${{ matrix.arch }} --compiler msvc-16
126126
127127
windows-vc15:
128-
runs-on: windows-2022 # latest
128+
runs-on: windows-2019 # windows-2019 is last env with Visual Studio 2017 (v15.0)
129129
strategy:
130130
matrix:
131131
arch: [x86, x64]

source/external/cJSON.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item)
127127
}
128128

129129
/* This is a safeguard to prevent copy-pasters from using incompatible C and header files */
130-
#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 17)
130+
#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 18)
131131
#error cJSON.h and cJSON.c have different versions. Make sure that both have the same.
132132
#endif
133133

@@ -273,10 +273,12 @@ CJSON_PUBLIC(void) cJSON_Delete(cJSON *item)
273273
if (!(item->type & cJSON_IsReference) && (item->valuestring != NULL))
274274
{
275275
global_hooks.deallocate(item->valuestring);
276+
item->valuestring = NULL;
276277
}
277278
if (!(item->type & cJSON_StringIsConst) && (item->string != NULL))
278279
{
279280
global_hooks.deallocate(item->string);
281+
item->string = NULL;
280282
}
281283
global_hooks.deallocate(item);
282284
item = next;
@@ -407,6 +409,7 @@ CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number)
407409
return object->valuedouble = number;
408410
}
409411

412+
/* Note: when passing a NULL valuestring, cJSON_SetValuestring treats this as an error and return NULL */
410413
CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring)
411414
{
412415
char *copy = NULL;
@@ -415,8 +418,8 @@ CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring)
415418
{
416419
return NULL;
417420
}
418-
/* return NULL if the object is corrupted */
419-
if (object->valuestring == NULL)
421+
/* return NULL if the object is corrupted or valuestring is NULL */
422+
if (object->valuestring == NULL || valuestring == NULL)
420423
{
421424
return NULL;
422425
}
@@ -903,6 +906,7 @@ static cJSON_bool parse_string(cJSON * const item, parse_buffer * const input_bu
903906
if (output != NULL)
904907
{
905908
input_buffer->hooks.deallocate(output);
909+
output = NULL;
906910
}
907911

908912
if (input_pointer != NULL)
@@ -1249,6 +1253,7 @@ static unsigned char *print(const cJSON * const item, cJSON_bool format, const i
12491253

12501254
/* free the buffer */
12511255
hooks->deallocate(buffer->buffer);
1256+
buffer->buffer = NULL;
12521257
}
12531258

12541259
return printed;
@@ -1257,11 +1262,13 @@ static unsigned char *print(const cJSON * const item, cJSON_bool format, const i
12571262
if (buffer->buffer != NULL)
12581263
{
12591264
hooks->deallocate(buffer->buffer);
1265+
buffer->buffer = NULL;
12601266
}
12611267

12621268
if (printed != NULL)
12631269
{
12641270
hooks->deallocate(printed);
1271+
printed = NULL;
12651272
}
12661273

12671274
return NULL;
@@ -1302,6 +1309,7 @@ CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON
13021309
if (!print_value(item, &p))
13031310
{
13041311
global_hooks.deallocate(p.buffer);
1312+
p.buffer = NULL;
13051313
return NULL;
13061314
}
13071315

@@ -1673,6 +1681,11 @@ static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_bu
16731681
current_item = new_item;
16741682
}
16751683

1684+
if (cannot_access_at_index(input_buffer, 1))
1685+
{
1686+
goto fail; /* nothing comes after the comma */
1687+
}
1688+
16761689
/* parse the name of the child */
16771690
input_buffer->offset++;
16781691
buffer_skip_whitespace(input_buffer);
@@ -3140,6 +3153,7 @@ CJSON_PUBLIC(void *) cJSON_malloc(size_t size)
31403153
CJSON_PUBLIC(void) cJSON_free(void *object)
31413154
{
31423155
global_hooks.deallocate(object);
3156+
object = NULL;
31433157
}
31443158
/* Amazon edit */
31453159
/* NOLINTEND */

source/external/cJSON.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJ
8888
/* project version */
8989
#define CJSON_VERSION_MAJOR 1
9090
#define CJSON_VERSION_MINOR 7
91-
#define CJSON_VERSION_PATCH 17
91+
#define CJSON_VERSION_PATCH 18
9292

9393
#include <stddef.h>
9494

0 commit comments

Comments
 (0)