From 16cad486412629586daf3d45e69079920d1548c2 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 7 Oct 2021 21:23:51 +0200 Subject: [PATCH] command/QueueCommands: validate the "addid" position before adding the song Validate early, so we avoid the rollback if an error occurs. --- src/command/QueueCommands.cxx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/command/QueueCommands.cxx b/src/command/QueueCommands.cxx index c9a8417a4..5e24c0919 100644 --- a/src/command/QueueCommands.cxx +++ b/src/command/QueueCommands.cxx @@ -113,12 +113,17 @@ handle_addid(Client &client, Request args, Response &r) const char *const uri = args.front(); auto &partition = client.GetPartition(); + + int to = -1; + if (args.size > 1) { + const auto queue_length = partition.playlist.queue.GetLength(); + to = args.ParseUnsigned(1, queue_length); + } + const SongLoader loader(client); unsigned added_id = partition.AppendURI(loader, uri); - if (args.size == 2) { - unsigned to = args.ParseUnsigned(1); - + if (to >= 0) { try { partition.MoveId(added_id, to); } catch (...) {