Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 19396a4

Browse files
committed
update comments and add tests for cJSON_SetValuestring
1 parent 5671646 commit 19396a4

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

‎cJSON.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number)
397397
return object->valuedouble = number;
398398
}
399399

400+
/* Note: when passing a NULL valuestring, cJSON_SetValuestring treats this as an error and return NULL */
400401
CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring)
401402
{
402403
char *copy = NULL;
@@ -405,7 +406,7 @@ CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring)
405406
{
406407
return NULL;
407408
}
408-
/* return NULL if the object is corrupted */
409+
/* return NULL if the object is corrupted or valuestring is NULL */
409410
if (object->valuestring == NULL || valuestring == NULL)
410411
{
411412
return NULL;

‎tests/misc_tests.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ static void cjson_functions_should_not_crash_with_null_pointers(void)
444444
TEST_ASSERT_FALSE(cJSON_Compare(NULL, item, false));
445445
TEST_ASSERT_NULL(cJSON_SetValuestring(NULL, "test"));
446446
TEST_ASSERT_NULL(cJSON_SetValuestring(corruptedString, "test"));
447+
TEST_ASSERT_NULL(cJSON_SetValuestring(item, NULL));
447448
cJSON_Minify(NULL);
448449
/* skipped because it is only used via a macro that checks for NULL */
449450
/* cJSON_SetNumberHelper(NULL, 0); */

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /