From 541593e9862c0311b235dd81f32a1c9bc660c5a1 Mon Sep 17 00:00:00 2001 From: Oleksiy Yakovenko Date: Fri, 2 Feb 2024 20:57:09 +0100 Subject: [PATCH] fix tests --- shared/undo/undobuffer.c | 6 ++++++ src/sort.c | 28 ++++++++++++++++------------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/shared/undo/undobuffer.c b/shared/undo/undobuffer.c index c2fe34bc73..a1cc5e6621 100644 --- a/shared/undo/undobuffer.c +++ b/shared/undo/undobuffer.c @@ -97,11 +97,17 @@ ddb_undobuffer_has_operations(ddb_undobuffer_t *undobuffer) { void ddb_undobuffer_group_begin (ddb_undobuffer_t *undobuffer) { + if (undobuffer == NULL) { + return; + } undobuffer->grouping = 1; } void ddb_undobuffer_group_end (ddb_undobuffer_t *undobuffer) { + if (undobuffer == NULL) { + return; + } undobuffer->grouping = 0; } diff --git a/src/sort.c b/src/sort.c index 636771c000..5b36f9534c 100644 --- a/src/sort.c +++ b/src/sort.c @@ -47,26 +47,30 @@ plt_sort_v2 (playlist_t *plt, int iter, int id, const char *format, int order) { if (plt->undo_enabled) { pl_lock (); int count = plt->count[PL_MAIN]; - playItem_t **tracks = calloc (count, sizeof (playItem_t *)); - int index = 0; - for (playItem_t *it = plt->head[PL_MAIN]; it != NULL; it = it->next[PL_MAIN]) { - tracks[index++] = it; + if (count != 0) { + playItem_t **tracks = calloc (count, sizeof (playItem_t *)); + int index = 0; + for (playItem_t *it = plt->head[PL_MAIN]; it != NULL; it = it->next[PL_MAIN]) { + tracks[index++] = it; + } + undo_remove_items(undobuffer, plt, tracks, count); + free (tracks); } - undo_remove_items(undobuffer, plt, tracks, count); - free (tracks); } plt_sort_internal (plt, iter, id, format, order, 1); if (plt->undo_enabled) { int count = plt->count[PL_MAIN]; - playItem_t **tracks = calloc (count, sizeof (playItem_t *)); - int index = 0; - for (playItem_t *it = plt->head[PL_MAIN]; it != NULL; it = it->next[PL_MAIN]) { - tracks[index++] = it; + if (count != 0) { + playItem_t **tracks = calloc (count, sizeof (playItem_t *)); + int index = 0; + for (playItem_t *it = plt->head[PL_MAIN]; it != NULL; it = it->next[PL_MAIN]) { + tracks[index++] = it; + } + undo_insert_items(undobuffer, plt, tracks, count); + free (tracks); } - undo_insert_items(undobuffer, plt, tracks, count); - free (tracks); pl_unlock (); } }