Skip to content

Commit

Permalink
feat: add tests for DaveGamble#842
Browse files Browse the repository at this point in the history
Add some tests for setting NULL to deallocated pointers
releated to DaveGamble#842 and DaveGamble#833
  • Loading branch information
Alanscut committed May 9, 2024
1 parent 752c343 commit 5b8ec9e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/misc_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,20 @@ static void cjson_set_bool_value_must_not_break_objects(void)
cJSON_Delete(sobj);
}

static void deallocated_pointers_should_be_set_to_null(void)
{
/* deallocated pointers should be set to null */
cJSON *string = cJSON_CreateString("item");
cJSON *root = cJSON_CreateObject();

cJSON_Delete(string);
free(string->valuestring);

cJSON_AddObjectToObject(root, "object");
cJSON_Delete(root->child);
free(root->child->string);
}

int CJSON_CDECL main(void)
{
UNITY_BEGIN();
Expand Down Expand Up @@ -762,6 +776,7 @@ int CJSON_CDECL main(void)
RUN_TEST(cjson_delete_item_from_array_should_not_broken_list_structure);
RUN_TEST(cjson_set_valuestring_to_object_should_not_leak_memory);
RUN_TEST(cjson_set_bool_value_must_not_break_objects);
RUN_TEST(deallocated_pointers_should_be_set_to_null);

return UNITY_END();
}

0 comments on commit 5b8ec9e

Please sign in to comment.