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 b47edc4

Browse files
vwvwAlanscut
authored andcommitted
CJSON_SetValuestring: add test for overlapping string
1 parent d6d5449 commit b47edc4

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

‎tests/misc_tests.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,19 @@ static void cjson_functions_should_not_crash_with_null_pointers(void)
471471
cJSON_Delete(item);
472472
}
473473

474+
static void cjson_set_valuestring_should_return_null_if_strings_overlap(void)
475+
{
476+
cJSON *obj, *obj_dup;
477+
char* str;
478+
479+
obj = cJSON_Parse("\"fooz\"");
480+
obj_dup = cJSON_Duplicate(obj, 1);
481+
482+
str = cJSON_SetValuestring(obj_dup, "beeez");
483+
cJSON_SetValuestring(obj_dup, str);
484+
cJSON_SetValuestring(obj_dup, ++str);
485+
}
486+
474487
static void *CJSON_CDECL failing_realloc(void *pointer, size_t size)
475488
{
476489
(void)size;
@@ -765,6 +778,7 @@ int CJSON_CDECL main(void)
765778
RUN_TEST(cjson_replace_item_via_pointer_should_replace_items);
766779
RUN_TEST(cjson_replace_item_in_object_should_preserve_name);
767780
RUN_TEST(cjson_functions_should_not_crash_with_null_pointers);
781+
RUN_TEST(cjson_set_valuestring_should_return_null_if_strings_overlap);
768782
RUN_TEST(ensure_should_fail_on_failed_realloc);
769783
RUN_TEST(skip_utf8_bom_should_skip_bom);
770784
RUN_TEST(skip_utf8_bom_should_not_skip_bom_if_not_at_beginning);

0 commit comments

Comments
(0)

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