@@ -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 */
410413CJSON_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)
31403153CJSON_PUBLIC (void ) cJSON_free (void * object )
31413154{
31423155 global_hooks .deallocate (object );
3156+ object = NULL ;
31433157}
31443158/* Amazon edit */
31453159/* NOLINTEND */
0 commit comments