diff --git a/gtk/Application.cc b/gtk/Application.cc index ef47f3791..a2a3b42bc 100644 --- a/gtk/Application.cc +++ b/gtk/Application.cc @@ -348,8 +348,9 @@ bool Application::Impl::refresh_actions() gtr_action_set_sensitive("open-torrent-folder", sel_counts.total_count == 1); gtr_action_set_sensitive("copy-magnet-link-to-clipboard", sel_counts.total_count == 1); - bool const can_update = wind_->for_each_selected_torrent_until( - [](auto const& torrent) { return tr_torrentCanManualUpdate(&torrent->get_underlying()); }); + bool const can_update = wind_ != nullptr && + wind_->for_each_selected_torrent_until([](auto const& torrent) + { return tr_torrentCanManualUpdate(&torrent->get_underlying()); }); gtr_action_set_sensitive("torrent-reannounce", can_update); } diff --git a/gtk/FilterBar.cc b/gtk/FilterBar.cc index 6f22b09dc..e7cb22308 100644 --- a/gtk/FilterBar.cc +++ b/gtk/FilterBar.cc @@ -302,7 +302,7 @@ bool FilterBar::Impl::tracker_filter_model_update() auto path = tracker_model_->get_path(add); core_->favicon_cache().load( site.announce_url, - [this, path](auto const* pixbuf) { favicon_ready_cb(pixbuf, path); }); + [this, path = std::move(path)](auto const* pixbuf) { favicon_ready_cb(pixbuf, path); }); ++i; } else // update row diff --git a/gtk/Utils.h b/gtk/Utils.h index fd04b7949..919daf30b 100644 --- a/gtk/Utils.h +++ b/gtk/Utils.h @@ -280,7 +280,7 @@ T* gtr_get_widget_derived(Glib::RefPtr const& builder, Glib::ustri template void gtr_window_on_close(Gtk::Window& widget, F&& callback) { - auto bool_callback = [callback]() mutable -> bool + auto bool_callback = [callback = std::move(callback)]() mutable -> bool { if constexpr (std::is_same_v>) { diff --git a/libtransmission/announcer.cc b/libtransmission/announcer.cc index ae0f1b309..34bc492a7 100644 --- a/libtransmission/announcer.cc +++ b/libtransmission/announcer.cc @@ -713,7 +713,7 @@ tr_torrent_announcer* tr_announcer_impl::addTorrent(tr_torrent* tor, tr_tracker_ TR_ASSERT(tr_isTorrent(tor)); auto* ta = new tr_torrent_announcer{ this, tor }; - ta->callback = callback; + ta->callback = std::move(callback); return ta; } diff --git a/libtransmission/file-capacity.cc b/libtransmission/file-capacity.cc index 706824cd1..88338b8e5 100644 --- a/libtransmission/file-capacity.cc +++ b/libtransmission/file-capacity.cc @@ -3,6 +3,7 @@ // or any future license endorsed by Mnemosyne LLC. // License text can be found in the licenses/ folder. +#include #include #include #include @@ -364,12 +365,12 @@ extern "C" int64_t const freespace = limit - spaceused; #ifdef __APPLE__ - disk_space.free = freespace < 0 ? 0 : freespace; - disk_space.total = limit < 0 ? 0 : limit; + disk_space.free = std::max(int64_t{ 0 }, freespace); + disk_space.total = std::max(int64_t{ 0 }, limit); return disk_space; #else - disk_space.free = freespace < 0 ? 0 : (freespace * 1024); - disk_space.total = limit < 0 ? 0 : (limit * 1024); + disk_space.free = std::max(int64_t{ 0 }, freespace * 1024); + disk_space.total = std::max(int64_t{ 0 }, limit * 1024); return disk_space; #endif } diff --git a/libtransmission/session.cc b/libtransmission/session.cc index cf8b8588b..8475e52f6 100644 --- a/libtransmission/session.cc +++ b/libtransmission/session.cc @@ -93,17 +93,25 @@ void bandwidthGroupRead(tr_session* session, std::string_view config_dir) auto& group = session->getBandwidthGroup(name); auto limits = tr_bandwidth_limits{}; - tr_variantDictFindBool(dict, TR_KEY_uploadLimited, &limits.up_limited); - tr_variantDictFindBool(dict, TR_KEY_downloadLimited, &limits.down_limited); - if (auto limit = int64_t{}; tr_variantDictFindInt(dict, TR_KEY_uploadLimit, &limit)) + if (auto val = bool{}; tr_variantDictFindBool(dict, TR_KEY_uploadLimited, &val)) { - limits.up_limit_KBps = static_cast(limit); + limits.up_limited = val; } - if (auto limit = int64_t{}; tr_variantDictFindInt(dict, TR_KEY_downloadLimit, &limit)) + if (auto val = bool{}; tr_variantDictFindBool(dict, TR_KEY_downloadLimited, &val)) { - limits.down_limit_KBps = static_cast(limit); + limits.down_limited = val; + } + + if (auto val = int64_t{}; tr_variantDictFindInt(dict, TR_KEY_uploadLimit, &val)) + { + limits.up_limit_KBps = static_cast(val); + } + + if (auto val = int64_t{}; tr_variantDictFindInt(dict, TR_KEY_downloadLimit, &val)) + { + limits.down_limit_KBps = static_cast(val); } group.set_limits(&limits); diff --git a/libtransmission/tr-udp.cc b/libtransmission/tr-udp.cc index 0732470c0..b11a2db55 100644 --- a/libtransmission/tr-udp.cc +++ b/libtransmission/tr-udp.cc @@ -152,7 +152,7 @@ tr_session::tr_udp_core::tr_udp_core(tr_session& session, tr_port udp_port) if (auto sock = socket(PF_INET, SOCK_DGRAM, 0); sock != TR_BAD_SOCKET) { auto optval = int{ 1 }; - setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast(&optval), sizeof(optval)); + (void)setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast(&optval), sizeof(optval)); auto const addr = session_.bind_address(TR_AF_INET); auto const [ss, sslen] = tr_socket_address::to_sockaddr(addr, udp_port_); diff --git a/libtransmission/utils.h b/libtransmission/utils.h index d57669e41..82df2e0b2 100644 --- a/libtransmission/utils.h +++ b/libtransmission/utils.h @@ -114,7 +114,7 @@ size_t tr_strlcpy(void* dst, void const* src, size_t siz); template [[nodiscard]] std::string tr_strlower(T in) { - auto out = std::string{ in }; + auto out = std::string{ std::move(in) }; std::for_each(std::begin(out), std::end(out), [](char& ch) { ch = std::tolower(ch); }); return out; } @@ -122,7 +122,7 @@ template template [[nodiscard]] std::string tr_strupper(T in) { - auto out = std::string{ in }; + auto out = std::string{ std::move(in) }; std::for_each(std::begin(out), std::end(out), [](char& ch) { ch = std::toupper(ch); }); return out; } diff --git a/tests/libtransmission/announce-list-test.cc b/tests/libtransmission/announce-list-test.cc index 61bd54323..a47168712 100644 --- a/tests/libtransmission/announce-list-test.cc +++ b/tests/libtransmission/announce-list-test.cc @@ -337,7 +337,7 @@ TEST_F(AnnounceListTest, announceToScrape) { "udp://www.example.com:999/"sv, "udp://www.example.com:999/"sv }, } }; - for (auto const test : Tests) + for (auto const& test : Tests) { auto const scrape = tr_announce_list::announce_to_scrape(tr_quark_new(test.announce)); EXPECT_EQ(tr_quark_new(test.expected_scrape), scrape); diff --git a/tests/libtransmission/file-test.cc b/tests/libtransmission/file-test.cc index 71f3d5fff..109aad6d2 100644 --- a/tests/libtransmission/file-test.cc +++ b/tests/libtransmission/file-test.cc @@ -266,7 +266,7 @@ TEST_F(FileTest, getInfo) { // Can't get info of non-existent file/directory info = tr_sys_path_get_info(path1, 0, &err); - ASSERT_FALSE(info.has_value()); + EXPECT_FALSE(info.has_value()); EXPECT_NE(nullptr, err); tr_error_clear(&err); diff --git a/utils/remote.cc b/utils/remote.cc index 0f024a4c0..821ec8f51 100644 --- a/utils/remote.cc +++ b/utils/remote.cc @@ -1492,8 +1492,8 @@ static void printTorrentList(tr_variant* top) [](tr_variant* f, tr_variant* s) { int64_t f_time = INT64_MIN, s_time = INT64_MIN; - tr_variantDictFindInt(f, TR_KEY_addedDate, &f_time); - tr_variantDictFindInt(s, TR_KEY_addedDate, &s_time); + (void)tr_variantDictFindInt(f, TR_KEY_addedDate, &f_time); + (void)tr_variantDictFindInt(s, TR_KEY_addedDate, &s_time); return f_time < s_time; }); @@ -2170,10 +2170,8 @@ static int processResponse(char const* rpcurl, std::string_view response, Config else { auto& top = *otop; - int64_t tag = -1; - auto sv = std::string_view{}; - if (tr_variantDictFindStrView(&top, TR_KEY_result, &sv)) + if (auto sv = std::string_view{}; tr_variantDictFindStrView(&top, TR_KEY_result, &sv)) { if (sv != "success"sv) { @@ -2182,7 +2180,8 @@ static int processResponse(char const* rpcurl, std::string_view response, Config } else { - tr_variantDictFindInt(&top, TR_KEY_tag, &tag); + int64_t tag = -1; + (void)tr_variantDictFindInt(&top, TR_KEY_tag, &tag); switch (tag) {