Skip to content

Commit d65d9b7

Browse files
author
Fredrik Widlund
committed
add splice edge case
1 parent 82a8585 commit d65d9b7

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/dynamic/list.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ void list_splice(void *object1, void *object2)
107107
{
108108
list_item *to, *from;
109109

110+
if (object1 == object2)
111+
return;
112+
110113
to = list_object_item(object1);
111114
from = list_object_item(object2);
112115

test/list.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,26 @@ void unit()
140140
list_destruct(&l, NULL);
141141
}
142142

143+
void edge()
144+
{
145+
list l1;
146+
int *i;
147+
148+
list_construct(&l1);
149+
150+
i = list_push_back(&l1, (int[]){1}, sizeof (int));
151+
list_splice(i, i);
152+
list_destruct(&l1, NULL);
153+
}
154+
143155
int main()
144156
{
145157
const struct CMUnitTest tests[] = {
146158
cmocka_unit_test(core),
147159
cmocka_unit_test(object_release),
148160
cmocka_unit_test(alloc),
149-
cmocka_unit_test(unit)
161+
cmocka_unit_test(unit),
162+
cmocka_unit_test(edge)
150163
};
151164

152165
return cmocka_run_group_tests(tests, NULL, NULL);

0 commit comments

Comments
 (0)