1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-01-30 10:52:00 +00:00

fix: minor coverity warnings (#5916)

* fix: unchecked return value from tr_variantDictFindInt()

coverity 1541113

* fix: unchecked return value from tr_variantDictFindBool()

coverity 1541112

* fix: copy-instead-of-move in tr_strlower()

coverity 1541092

* fix: use auto& instead of auto in test

coverity 1541084

* fix: logically dead code

coverity 1541065

* fix: copy-instead-of-move in tr_announcer_impl::addTorrent()

coverity 1541062

* fix: unchecked return value of tr_variantDictFindInt()

coverity 1541061

* fix: copy-instead-of-move in FilterBar::Impl::tracker_filter_model_update()

coverity 1541058

* fix: copy-instead-of-move in gtr_window_on_close()

* fix: silence invalid resource leak warning

coverity 1520595

* fix: unchecked return value from setsockopt()

coverity 1518345

* fix: dereference after null check (FORWARD_NULL)

coverity 1517816
This commit is contained in:
Charles Kerr 2023-08-21 21:59:47 -05:00 committed by GitHub
parent 59c638c63d
commit fbfbfac3ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 35 additions and 26 deletions

View file

@ -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("open-torrent-folder", sel_counts.total_count == 1);
gtr_action_set_sensitive("copy-magnet-link-to-clipboard", 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( bool const can_update = wind_ != nullptr &&
[](auto const& torrent) { return tr_torrentCanManualUpdate(&torrent->get_underlying()); }); wind_->for_each_selected_torrent_until([](auto const& torrent)
{ return tr_torrentCanManualUpdate(&torrent->get_underlying()); });
gtr_action_set_sensitive("torrent-reannounce", can_update); gtr_action_set_sensitive("torrent-reannounce", can_update);
} }

View file

@ -302,7 +302,7 @@ bool FilterBar::Impl::tracker_filter_model_update()
auto path = tracker_model_->get_path(add); auto path = tracker_model_->get_path(add);
core_->favicon_cache().load( core_->favicon_cache().load(
site.announce_url, 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; ++i;
} }
else // update row else // update row

View file

@ -280,7 +280,7 @@ T* gtr_get_widget_derived(Glib::RefPtr<Gtk::Builder> const& builder, Glib::ustri
template<typename F> template<typename F>
void gtr_window_on_close(Gtk::Window& widget, F&& callback) 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<void, std::invoke_result_t<decltype(callback)>>) if constexpr (std::is_same_v<void, std::invoke_result_t<decltype(callback)>>)
{ {

View file

@ -713,7 +713,7 @@ tr_torrent_announcer* tr_announcer_impl::addTorrent(tr_torrent* tor, tr_tracker_
TR_ASSERT(tr_isTorrent(tor)); TR_ASSERT(tr_isTorrent(tor));
auto* ta = new tr_torrent_announcer{ this, tor }; auto* ta = new tr_torrent_announcer{ this, tor };
ta->callback = callback; ta->callback = std::move(callback);
return ta; return ta;
} }

View file

@ -3,6 +3,7 @@
// or any future license endorsed by Mnemosyne LLC. // or any future license endorsed by Mnemosyne LLC.
// License text can be found in the licenses/ folder. // License text can be found in the licenses/ folder.
#include <algorithm>
#include <cerrno> #include <cerrno>
#include <string> #include <string>
#include <string_view> #include <string_view>
@ -364,12 +365,12 @@ extern "C"
int64_t const freespace = limit - spaceused; int64_t const freespace = limit - spaceused;
#ifdef __APPLE__ #ifdef __APPLE__
disk_space.free = freespace < 0 ? 0 : freespace; disk_space.free = std::max(int64_t{ 0 }, freespace);
disk_space.total = limit < 0 ? 0 : limit; disk_space.total = std::max(int64_t{ 0 }, limit);
return disk_space; return disk_space;
#else #else
disk_space.free = freespace < 0 ? 0 : (freespace * 1024); disk_space.free = std::max(int64_t{ 0 }, freespace * 1024);
disk_space.total = limit < 0 ? 0 : (limit * 1024); disk_space.total = std::max(int64_t{ 0 }, limit * 1024);
return disk_space; return disk_space;
#endif #endif
} }

View file

@ -93,17 +93,25 @@ void bandwidthGroupRead(tr_session* session, std::string_view config_dir)
auto& group = session->getBandwidthGroup(name); auto& group = session->getBandwidthGroup(name);
auto limits = tr_bandwidth_limits{}; 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<tr_kilobytes_per_second_t>(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<tr_kilobytes_per_second_t>(limit); limits.down_limited = val;
}
if (auto val = int64_t{}; tr_variantDictFindInt(dict, TR_KEY_uploadLimit, &val))
{
limits.up_limit_KBps = static_cast<tr_kilobytes_per_second_t>(val);
}
if (auto val = int64_t{}; tr_variantDictFindInt(dict, TR_KEY_downloadLimit, &val))
{
limits.down_limit_KBps = static_cast<tr_kilobytes_per_second_t>(val);
} }
group.set_limits(&limits); group.set_limits(&limits);

View file

@ -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) if (auto sock = socket(PF_INET, SOCK_DGRAM, 0); sock != TR_BAD_SOCKET)
{ {
auto optval = int{ 1 }; auto optval = int{ 1 };
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<char const*>(&optval), sizeof(optval)); (void)setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<char const*>(&optval), sizeof(optval));
auto const addr = session_.bind_address(TR_AF_INET); auto const addr = session_.bind_address(TR_AF_INET);
auto const [ss, sslen] = tr_socket_address::to_sockaddr(addr, udp_port_); auto const [ss, sslen] = tr_socket_address::to_sockaddr(addr, udp_port_);

View file

@ -114,7 +114,7 @@ size_t tr_strlcpy(void* dst, void const* src, size_t siz);
template<typename T> template<typename T>
[[nodiscard]] std::string tr_strlower(T in) [[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); }); std::for_each(std::begin(out), std::end(out), [](char& ch) { ch = std::tolower(ch); });
return out; return out;
} }
@ -122,7 +122,7 @@ template<typename T>
template<typename T> template<typename T>
[[nodiscard]] std::string tr_strupper(T in) [[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); }); std::for_each(std::begin(out), std::end(out), [](char& ch) { ch = std::toupper(ch); });
return out; return out;
} }

View file

@ -337,7 +337,7 @@ TEST_F(AnnounceListTest, announceToScrape)
{ "udp://www.example.com:999/"sv, "udp://www.example.com:999/"sv }, { "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)); auto const scrape = tr_announce_list::announce_to_scrape(tr_quark_new(test.announce));
EXPECT_EQ(tr_quark_new(test.expected_scrape), scrape); EXPECT_EQ(tr_quark_new(test.expected_scrape), scrape);

View file

@ -266,7 +266,7 @@ TEST_F(FileTest, getInfo)
{ {
// Can't get info of non-existent file/directory // Can't get info of non-existent file/directory
info = tr_sys_path_get_info(path1, 0, &err); info = tr_sys_path_get_info(path1, 0, &err);
ASSERT_FALSE(info.has_value()); EXPECT_FALSE(info.has_value());
EXPECT_NE(nullptr, err); EXPECT_NE(nullptr, err);
tr_error_clear(&err); tr_error_clear(&err);

View file

@ -1492,8 +1492,8 @@ static void printTorrentList(tr_variant* top)
[](tr_variant* f, tr_variant* s) [](tr_variant* f, tr_variant* s)
{ {
int64_t f_time = INT64_MIN, s_time = INT64_MIN; int64_t f_time = INT64_MIN, s_time = INT64_MIN;
tr_variantDictFindInt(f, TR_KEY_addedDate, &f_time); (void)tr_variantDictFindInt(f, TR_KEY_addedDate, &f_time);
tr_variantDictFindInt(s, TR_KEY_addedDate, &s_time); (void)tr_variantDictFindInt(s, TR_KEY_addedDate, &s_time);
return f_time < s_time; return f_time < s_time;
}); });
@ -2170,10 +2170,8 @@ static int processResponse(char const* rpcurl, std::string_view response, Config
else else
{ {
auto& top = *otop; 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) if (sv != "success"sv)
{ {
@ -2182,7 +2180,8 @@ static int processResponse(char const* rpcurl, std::string_view response, Config
} }
else else
{ {
tr_variantDictFindInt(&top, TR_KEY_tag, &tag); int64_t tag = -1;
(void)tr_variantDictFindInt(&top, TR_KEY_tag, &tag);
switch (tag) switch (tag)
{ {