Skip to content

Commit

Permalink
List: don't memmove when deleting the last entry
Browse files Browse the repository at this point in the history
  • Loading branch information
Noam Preil committed Sep 11, 2020
1 parent e746eaa commit 01d5c42
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions common/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ void list_insert(list_t *list, int index, void *item) {

void list_del(list_t *list, int index) {
list->length--;
memmove(&list->items[index], &list->items[index + 1], sizeof(void*) * (list->length - index));
if (index != list->length) {
memmove(&list->items[index], &list->items[index + 1], sizeof(void*) * (list->length - index));
}
}

void list_cat(list_t *list, list_t *source) {
int i;
for (i = 0; i < source->length; ++i) {
for (int i = 0; i < source->length; ++i) {
list_add(list, source->items[i]);
}
}
Expand Down

0 comments on commit 01d5c42

Please sign in to comment.