Skip to content

Commit 9f023fc

Browse files
author
Noam Preil
committed
List: don't memmove when deleting the last entry
1 parent db9ceb2 commit 9f023fc

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

common/list.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ void list_insert(list_t *list, int index, void *item) {
4949

5050
void list_del(list_t *list, int index) {
5151
list->length--;
52-
memmove(&list->items[index], &list->items[index + 1], sizeof(void*) * (list->length - index));
52+
if (index != list->length) {
53+
memmove(&list->items[index], &list->items[index + 1], sizeof(void*) * (list->length - index));
54+
}
5355
}
5456

5557
void list_cat(list_t *list, list_t *source) {
56-
int i;
57-
for (i = 0; i < source->length; ++i) {
58+
for (int i = 0; i < source->length; ++i) {
5859
list_add(list, source->items[i]);
5960
}
6061
}

0 commit comments

Comments
 (0)