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 4f4d7f7

Browse files
vwvwAlanscut
authored andcommitted
CJSON_SetValuestring: better test for overlapping string
1 parent b47edc4 commit 4f4d7f7

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

‎tests/misc_tests.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -473,15 +473,19 @@ static void cjson_functions_should_not_crash_with_null_pointers(void)
473473

474474
static void cjson_set_valuestring_should_return_null_if_strings_overlap(void)
475475
{
476-
cJSON *obj, *obj_dup;
476+
cJSON *obj;
477477
char* str;
478+
char* str2;
478479

479-
obj = cJSON_Parse("\"fooz\"");
480-
obj_dup = cJSON_Duplicate(obj, 1);
480+
obj = cJSON_Parse("\"foo0z\"");
481481

482-
str = cJSON_SetValuestring(obj_dup, "beeez");
483-
cJSON_SetValuestring(obj_dup, str);
484-
cJSON_SetValuestring(obj_dup, ++str);
482+
str = cJSON_SetValuestring(obj, "abcde");
483+
str += 1;
484+
/* The string passed to strcpy overlap which is not allowed.*/
485+
str2 = cJSON_SetValuestring(obj, str);
486+
/* If it overlaps, the string will be messed up.*/
487+
TEST_ASSERT_TRUE(strcmp(str, "bcde") == 0);
488+
TEST_ASSERT_NULL(str2);
485489
}
486490

487491
static void *CJSON_CDECL failing_realloc(void *pointer, size_t size)

0 commit comments

Comments
(0)

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