@@ -280,6 +280,21 @@ static void cjson_detach_item_via_pointer_should_detach_items(void)
280
280
TEST_ASSERT_NULL_MESSAGE (parent -> child , "Child of the parent wasn't set to NULL." );
281
281
}
282
282
283
+ static void cjson_detach_item_via_pointer_should_return_null_if_item_prev_is_null (void )
284
+ {
285
+ cJSON list [2 ];
286
+ cJSON parent [1 ];
287
+
288
+ memset (list , '0円' , sizeof (list ));
289
+
290
+ /* link the list */
291
+ list [0 ].next = & (list [1 ]);
292
+
293
+ parent -> child = & list [0 ];
294
+ TEST_ASSERT_NULL_MESSAGE (cJSON_DetachItemViaPointer (parent , & (list [1 ])), "Failed to detach in the middle." );
295
+ TEST_ASSERT_TRUE_MESSAGE (cJSON_DetachItemViaPointer (parent , & (list [0 ])) == & (list [0 ]), "Failed to detach in the middle." );
296
+ }
297
+
283
298
static void cjson_replace_item_via_pointer_should_replace_items (void )
284
299
{
285
300
cJSON replacements [3 ];
@@ -746,6 +761,7 @@ int CJSON_CDECL main(void)
746
761
RUN_TEST (cjson_should_not_parse_to_deeply_nested_jsons );
747
762
RUN_TEST (cjson_set_number_value_should_set_numbers );
748
763
RUN_TEST (cjson_detach_item_via_pointer_should_detach_items );
764
+ RUN_TEST (cjson_detach_item_via_pointer_should_return_null_if_item_prev_is_null );
749
765
RUN_TEST (cjson_replace_item_via_pointer_should_replace_items );
750
766
RUN_TEST (cjson_replace_item_in_object_should_preserve_name );
751
767
RUN_TEST (cjson_functions_should_not_crash_with_null_pointers );
0 commit comments