Skip to content

Commit

Permalink
add splice edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredrik Widlund committed Oct 26, 2019
1 parent 82a8585 commit d65d9b7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/dynamic/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ void list_splice(void *object1, void *object2)
{
list_item *to, *from;

if (object1 == object2)
return;

to = list_object_item(object1);
from = list_object_item(object2);

Expand Down
15 changes: 14 additions & 1 deletion test/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,26 @@ void unit()
list_destruct(&l, NULL);
}

void edge()
{
list l1;
int *i;

list_construct(&l1);

i = list_push_back(&l1, (int[]){1}, sizeof (int));
list_splice(i, i);
list_destruct(&l1, NULL);
}

int main()
{
const struct CMUnitTest tests[] = {
cmocka_unit_test(core),
cmocka_unit_test(object_release),
cmocka_unit_test(alloc),
cmocka_unit_test(unit)
cmocka_unit_test(unit),
cmocka_unit_test(edge)
};

return cmocka_run_group_tests(tests, NULL, NULL);
Expand Down

0 comments on commit d65d9b7

Please sign in to comment.