diff options
author | Nicolas Badoux <n.badoux@hotmail.com> | 2024-08-25 22:32:02 +0200 |
---|---|---|
committer | Alan Wang <wp_scut@163.com> | 2024-08-30 11:29:28 +0800 |
commit | b47edc4750301a17bcc72bf20323d2f625a4ae05 (patch) | |
tree | 9bac607e76141081dfe403411b5a0b94ef29d3c5 | |
parent | d6d5449e1f271556ea8e6ec0f3026ceb0b4a9508 (diff) | |
download | cjson-b47edc4750301a17bcc72bf20323d2f625a4ae05.tar.gz cjson-b47edc4750301a17bcc72bf20323d2f625a4ae05.zip |
CJSON_SetValuestring: add test for overlapping string
-rw-r--r-- | tests/misc_tests.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/misc_tests.c b/tests/misc_tests.c index b9c59e7..b10c0a0 100644 --- a/tests/misc_tests.c +++ b/tests/misc_tests.c @@ -471,6 +471,19 @@ static void cjson_functions_should_not_crash_with_null_pointers(void) cJSON_Delete(item); } +static void cjson_set_valuestring_should_return_null_if_strings_overlap(void) +{ + cJSON *obj, *obj_dup; + char* str; + + obj = cJSON_Parse("\"fooz\""); + obj_dup = cJSON_Duplicate(obj, 1); + + str = cJSON_SetValuestring(obj_dup, "beeez"); + cJSON_SetValuestring(obj_dup, str); + cJSON_SetValuestring(obj_dup, ++str); +} + static void *CJSON_CDECL failing_realloc(void *pointer, size_t size) { (void)size; @@ -765,6 +778,7 @@ int CJSON_CDECL main(void) RUN_TEST(cjson_replace_item_via_pointer_should_replace_items); RUN_TEST(cjson_replace_item_in_object_should_preserve_name); RUN_TEST(cjson_functions_should_not_crash_with_null_pointers); + RUN_TEST(cjson_set_valuestring_should_return_null_if_strings_overlap); RUN_TEST(ensure_should_fail_on_failed_realloc); RUN_TEST(skip_utf8_bom_should_skip_bom); RUN_TEST(skip_utf8_bom_should_not_skip_bom_if_not_at_beginning); |