From b9b2ed64f9f03c9231cbfa45c8192c597598e6cf Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 5 Apr 2022 11:42:18 +0800 Subject: [PATCH] Assign temporary data to a variable This is mainly to avoid dangerous code pattern: getting an iterator on a temporary object. Previously `data()` returns a const reference so the code wasn't doing any harm. --- src/webui/api/torrentscontroller.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/webui/api/torrentscontroller.cpp b/src/webui/api/torrentscontroller.cpp index 3c77c5edc..0c6869cc5 100644 --- a/src/webui/api/torrentscontroller.cpp +++ b/src/webui/api/torrentscontroller.cpp @@ -717,7 +717,8 @@ void TorrentsController::addAction() } } - for (auto it = data().constBegin(); it != data().constEnd(); ++it) + const DataMap torrents = data(); + for (auto it = torrents.constBegin(); it != torrents.constEnd(); ++it) { const nonstd::expected result = BitTorrent::TorrentInfo::load(it.value()); if (!result)