ap

An audio player suited to my tastes
Log | Files | Refs | README | LICENSE

commit 69d2da8ce9ddbf577d58629ac0d53a68a434f252
parent ad96092405729e8d71d542ab45d6021d72bdeb0f
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date:   Wed, 17 Jan 2024 22:21:43 -0800

Fix infinite search bug in remove command

The problem was that if the first item in the queue (which is also
the value of search.end) was removed in a non-numeric search, the
server looped the queue infinitely because it never found search.end.

Now I manually update search.end in that case aswell as set search.new
due to the internals of the searching functions work. In the future
I'd like to rework the interals of the search functions to allow a
more elegant solution.

Diffstat:
Maps/command.c | 29++++++++++++++++++++---------
1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/aps/command.c b/aps/command.c @@ -52,7 +52,7 @@ com_add(struct aps *aps, int fd, int argc, char **argv) char * com_remove(struct aps *aps, int fd, int argc, char **argv) { - struct item *item; + struct item *match, *next; struct search search; char *err; @@ -67,17 +67,28 @@ com_remove(struct aps *aps, int fd, int argc, char **argv) if (err) return err; - while ((item = findnext(&search))) { - if (aps_bufline(aps, fd, item->path)) + while ((match = findnext(&search))) { + if (aps_bufline(aps, fd, match->path)) return errstr; - if (item == aps->queue) { - item = queue_remove(aps, item); + + if (match == search.end) { + search.end = NULL; + } + + if (match == aps->queue) { + next = queue_remove(aps, match); } else { - item = queue_remove(aps, item); - if (item == aps->queue) - item = NULL; + next = queue_remove(aps, match); + if (next == aps->queue) + match = NULL; + } + + if (!search.end) { + search.end = next; + search.new = 1; } - if (item == NULL) + + if (next == NULL) break; }