fix: sonarcloud warnings (#2260)
* fix: add-explicit-keyword-to-constructor warning
Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX1tyuB-2farvsyMPiZl&open=AX1tyuB-2farvsyMPiZl
* fix: use a structured binding declaration
Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX1tyuHH2farvsyMPiZm&open=AX1tyuHH2farvsyMPiZm
* Fix implicit-conversion-loses-precision warning
Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX1tyuH22farvsyMPiZn&open=AX1tyuH22farvsyMPiZn
* fix use-init-statement warning
Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX1tyuO42farvsyMPiZw&open=AX1tyuO42farvsyMPiZw
* fix implicit-conversion-loses-precision warning
Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX1tyuO42farvsyMPiZs&open=AX1tyuO42farvsyMPiZs
* fix: implicit-conversion-loses-precision warning
Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX1tyuO42farvsyMPiZt&open=AX1tyuO42farvsyMPiZt
* fix handle-this-exceeption-or-do-not-catch-it warning
Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX1y7t12cIz3krp3mVpV&open=AX1y7t12cIz3krp3mVpV
* fix make-this-variable-a-reference-to-const warning
Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX1y7t12cIz3krp3mVpW&open=AX1y7t12cIz3krp3mVpW
* fix replace-redundant-type-with-auto warning
Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX1y7t12cIz3krp3mVpY&open=AX1y7t12cIz3krp3mVpY
* Fix use-try_emplace-instead-of-emplace warning
Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX0WPk3QwxvzFbF6whWN&open=AX0WPk3QwxvzFbF6whWN
* Fix: make-this-a-pointer-to-const warning
Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX0bZPUXjI_aUyxGBxB4&open=AX0bZPUXjI_aUyxGBxB4
* Fix use-std::make_unique warning
Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX0WPk0twxvzFbF6whWC&open=AX0WPk0twxvzFbF6whWC
* Fix: replace-push_back-with-emplace_back warning
Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX0BraL_0QLXO0pQ_Bfv&open=AX0BraL_0QLXO0pQ_Bfv
* Fix: use-init-statement warning
Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX0bZPXajI_aUyxGBxB8&open=AX0bZPXajI_aUyxGBxB8
* Fix: replace-redundant-type-with-auto warning
Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX0bZPXajI_aUyxGBxB9&open=AX0bZPXajI_aUyxGBxB9
* Fix: replace-emplace-with-try_emplace warning
Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX0bZPXajI_aUyxGBxB_&open=AX0bZPXajI_aUyxGBxB_
* Fix: extract-assignment-from-operation warning
Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX0bZPXajI_aUyxGBxCA&open=AX0bZPXajI_aUyxGBxCA
* Fix use-init-statement warning
Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX1op6_hUBCnp-Grmra8&open=AX1op6_hUBCnp-Grmra8
* fix: use-init-statement warning
Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX0L8qgMUnpKTxYiu5CN&open=AX0L8qgMUnpKTxYiu5CN
* Revert "Fix use-std::make_unique warning"
This reverts commit 463a742f34
.
* fix: make-parameter-a-pointer-to-const warning
Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX06St241usi2gyYkPTZ&open=AX06St241usi2gyYkPTZ
* fix: make-parameter-a-pointer-to-const warning
Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX06St241usi2gyYkPTa&open=AX06St241usi2gyYkPTa
* fix: use-init-statement warning
Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX01Itn2f_SST5i7BN1o&open=AX01Itn2f_SST5i7BN1o
* fix: use-init-statement warning
Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AXziv55-MuQoG-Y-NgLX&open=AXziv55-MuQoG-Y-NgLX
* fix: use-init-statement warning
Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX0_a_JGNJn7rAzml_68&open=AX0_a_JGNJn7rAzml_68
* fix: replace-redundant-type-with-auto warning
Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AXzyMRYbK9dvryvWm8XA&open=AXzyMRYbK9dvryvWm8XA
* fix: use-init-statement warning
Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AXziv52fMuQoG-Y-NgLW&open=AXziv52fMuQoG-Y-NgLW
This commit is contained in:
parent
933990fbfc
commit
2977636d58
|
@ -129,7 +129,7 @@ Glib::RefPtr<Gio::SimpleActionGroup> gtr_actions_init(Glib::RefPtr<Gtk::Builder>
|
|||
action->signal_activate().connect([a = gtr_get_ptr(action), callback_user_data](auto const& value)
|
||||
{ sort_changed_cb(*a, value, callback_user_data); });
|
||||
action_group->add_action(action);
|
||||
key_to_action.emplace(action_name, action);
|
||||
key_to_action.try_emplace(action_name, action);
|
||||
}
|
||||
|
||||
for (auto const& action_name_view : show_toggle_entries)
|
||||
|
@ -139,7 +139,7 @@ Glib::RefPtr<Gio::SimpleActionGroup> gtr_actions_init(Glib::RefPtr<Gtk::Builder>
|
|||
action->signal_activate().connect([a = gtr_get_ptr(action), callback_user_data](auto const& /*value*/)
|
||||
{ action_cb(*a, callback_user_data); });
|
||||
action_group->add_action(action);
|
||||
key_to_action.emplace(action_name, action);
|
||||
key_to_action.try_emplace(action_name, action);
|
||||
}
|
||||
|
||||
for (auto const& action_name_view : pref_toggle_entries)
|
||||
|
@ -149,7 +149,7 @@ Glib::RefPtr<Gio::SimpleActionGroup> gtr_actions_init(Glib::RefPtr<Gtk::Builder>
|
|||
action->signal_activate().connect([a = gtr_get_ptr(action), callback_user_data](auto const& /*value*/)
|
||||
{ toggle_pref_cb(*a, callback_user_data); });
|
||||
action_group->add_action(action);
|
||||
key_to_action.emplace(action_name, action);
|
||||
key_to_action.try_emplace(action_name, action);
|
||||
}
|
||||
|
||||
for (auto const& action_name_view : entries)
|
||||
|
@ -159,7 +159,7 @@ Glib::RefPtr<Gio::SimpleActionGroup> gtr_actions_init(Glib::RefPtr<Gtk::Builder>
|
|||
action->signal_activate().connect([a = gtr_get_ptr(action), callback_user_data](auto const& /*value*/)
|
||||
{ action_cb(*a, callback_user_data); });
|
||||
action_group->add_action(action);
|
||||
key_to_action.emplace(action_name, action);
|
||||
key_to_action.try_emplace(action_name, action);
|
||||
}
|
||||
|
||||
return action_group;
|
||||
|
|
|
@ -39,8 +39,7 @@ FreeSpaceLabel::Impl::~Impl()
|
|||
|
||||
bool FreeSpaceLabel::Impl::on_freespace_timer()
|
||||
{
|
||||
auto* const session = core_->get_session();
|
||||
if (session == nullptr)
|
||||
if (core_->get_session() == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -194,13 +194,13 @@ void gtr_notify_torrent_completed(Glib::RefPtr<Session> const& core, int torrent
|
|||
{
|
||||
if (tr_torrentFileCount(tor) == 1)
|
||||
{
|
||||
actions.push_back("file");
|
||||
actions.push_back(_("Open File"));
|
||||
actions.emplace_back("file");
|
||||
actions.emplace_back(_("Open File"));
|
||||
}
|
||||
else
|
||||
{
|
||||
actions.push_back("folder");
|
||||
actions.push_back(_("Open Folder"));
|
||||
actions.emplace_back("folder");
|
||||
actions.emplace_back(_("Open Folder"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -235,8 +235,8 @@ void gtr_notify_torrent_added(Glib::RefPtr<Session> const& core, int torrent_id)
|
|||
std::vector<Glib::ustring> actions;
|
||||
if (server_supports_actions)
|
||||
{
|
||||
actions.push_back("start-now");
|
||||
actions.push_back(_("Start Now"));
|
||||
actions.emplace_back("start-now");
|
||||
actions.emplace_back(_("Start Now"));
|
||||
}
|
||||
|
||||
auto const n = TrNotification{ core, torrent_id };
|
||||
|
|
|
@ -1639,9 +1639,7 @@ std::map<int64_t, std::function<void(tr_variant*)>> pendingRequests;
|
|||
|
||||
bool core_read_rpc_response_idle(tr_variant* response)
|
||||
{
|
||||
int64_t tag;
|
||||
|
||||
if (tr_variantDictFindInt(response, TR_KEY_tag, &tag))
|
||||
if (int64_t tag = 0; tr_variantDictFindInt(response, TR_KEY_tag, &tag))
|
||||
{
|
||||
if (auto const data_it = pendingRequests.find(tag); data_it != pendingRequests.end())
|
||||
{
|
||||
|
@ -1665,7 +1663,7 @@ bool core_read_rpc_response_idle(tr_variant* response)
|
|||
|
||||
void core_read_rpc_response(tr_session* /*session*/, tr_variant* response, void* /*user_data*/)
|
||||
{
|
||||
tr_variant* response_copy = new tr_variant(std::move(*response));
|
||||
auto* response_copy = new tr_variant(std::move(*response));
|
||||
|
||||
tr_variantInitBool(response, false);
|
||||
|
||||
|
@ -1686,7 +1684,7 @@ void Session::Impl::send_rpc_request(
|
|||
else
|
||||
{
|
||||
/* remember this request */
|
||||
pendingRequests.emplace(tag, response_func);
|
||||
pendingRequests.try_emplace(tag, response_func);
|
||||
|
||||
/* make the request */
|
||||
#ifdef DEBUG_RPC
|
||||
|
@ -1708,7 +1706,8 @@ void Session::Impl::send_rpc_request(
|
|||
|
||||
void Session::port_test()
|
||||
{
|
||||
auto const tag = nextTag++;
|
||||
auto const tag = nextTag;
|
||||
++nextTag;
|
||||
|
||||
tr_variant request;
|
||||
tr_variantInitDict(&request, 2);
|
||||
|
@ -1739,7 +1738,8 @@ void Session::port_test()
|
|||
|
||||
void Session::blocklist_update()
|
||||
{
|
||||
auto const tag = nextTag++;
|
||||
auto const tag = nextTag;
|
||||
++nextTag;
|
||||
|
||||
tr_variant request;
|
||||
tr_variantInitDict(&request, 2);
|
||||
|
@ -1775,7 +1775,8 @@ void Session::blocklist_update()
|
|||
|
||||
void Session::exec(tr_variant const* top)
|
||||
{
|
||||
auto const tag = nextTag++;
|
||||
auto const tag = nextTag;
|
||||
++nextTag;
|
||||
|
||||
impl_->send_rpc_request(top, tag, {});
|
||||
}
|
||||
|
|
|
@ -383,9 +383,8 @@ namespace
|
|||
Glib::RefPtr<Gdk::Pixbuf> get_icon(tr_torrent const* tor, Gtk::IconSize icon_size, Gtk::Widget& for_widget)
|
||||
{
|
||||
Glib::ustring mime_type;
|
||||
auto const n_files = tr_torrentFileCount(tor);
|
||||
|
||||
if (n_files == 0)
|
||||
if (auto const n_files = tr_torrentFileCount(tor); n_files == 0)
|
||||
{
|
||||
mime_type = UNKNOWN_MIME_TYPE;
|
||||
}
|
||||
|
|
|
@ -1230,9 +1230,8 @@ static void announce_request_delegate(
|
|||
|
||||
#endif
|
||||
|
||||
auto const announce_sv = tr_quark_get_string_view(request->announce_url);
|
||||
|
||||
if (tr_strvStartsWith(announce_sv, "http://"sv) || tr_strvStartsWith(announce_sv, "https://"sv))
|
||||
if (auto const announce_sv = tr_quark_get_string_view(request->announce_url);
|
||||
tr_strvStartsWith(announce_sv, "http://"sv) || tr_strvStartsWith(announce_sv, "https://"sv))
|
||||
{
|
||||
tr_tracker_http_announce(session, request, callback, callback_data);
|
||||
}
|
||||
|
|
|
@ -90,8 +90,8 @@ tr_file_piece_map::file_span_t tr_file_piece_map::fileSpan(tr_piece_index_t piec
|
|||
};
|
||||
|
||||
auto const begin = std::begin(files_);
|
||||
auto const pair = std::equal_range(begin, std::end(files_), piece, Compare{});
|
||||
return { tr_piece_index_t(std::distance(begin, pair.first)), tr_piece_index_t(std::distance(begin, pair.second)) };
|
||||
auto const& [equal_begin, equal_end] = std::equal_range(begin, std::end(files_), piece, Compare{});
|
||||
return { tr_piece_index_t(std::distance(begin, equal_begin)), tr_piece_index_t(std::distance(begin, equal_end)) };
|
||||
}
|
||||
|
||||
/***
|
||||
|
|
|
@ -32,7 +32,7 @@ public:
|
|||
using file_span_t = index_span_t<tr_file_index_t>;
|
||||
using piece_span_t = index_span_t<tr_piece_index_t>;
|
||||
|
||||
tr_file_piece_map(tr_info const& info)
|
||||
explicit tr_file_piece_map(tr_info const& info)
|
||||
{
|
||||
reset(info);
|
||||
}
|
||||
|
|
|
@ -556,7 +556,7 @@ static void updateEndgame(tr_swarm* s)
|
|||
s->endgame = uint64_t(std::size(s->active_requests)) * s->tor->block_size >= s->tor->leftUntilDone();
|
||||
}
|
||||
|
||||
std::vector<tr_block_span_t> tr_peerMgrGetNextRequests(tr_torrent* torrent, tr_peer* peer, size_t numwant)
|
||||
std::vector<tr_block_span_t> tr_peerMgrGetNextRequests(tr_torrent* torrent, tr_peer const* peer, size_t numwant)
|
||||
{
|
||||
class PeerInfoImpl : public Wishlist::PeerInfo
|
||||
{
|
||||
|
@ -647,7 +647,7 @@ static void maybeSendCancelRequest(tr_peer* peer, tr_block_index_t block, tr_pee
|
|||
}
|
||||
}
|
||||
|
||||
static void cancelAllRequestsForBlock(tr_swarm* swarm, tr_block_index_t block, tr_peer* no_notify)
|
||||
static void cancelAllRequestsForBlock(tr_swarm* swarm, tr_block_index_t block, tr_peer const* no_notify)
|
||||
{
|
||||
for (auto* peer : swarm->active_requests.remove(block))
|
||||
{
|
||||
|
|
|
@ -79,7 +79,7 @@ void tr_peerMgrSetUtpSupported(tr_torrent* tor, tr_address const* addr);
|
|||
|
||||
void tr_peerMgrSetUtpFailed(tr_torrent* tor, tr_address const* addr, bool failed);
|
||||
|
||||
std::vector<tr_block_span_t> tr_peerMgrGetNextRequests(tr_torrent* torrent, tr_peer* peer, size_t numwant);
|
||||
std::vector<tr_block_span_t> tr_peerMgrGetNextRequests(tr_torrent* torrent, tr_peer const* peer, size_t numwant);
|
||||
|
||||
bool tr_peerMgrDidPeerRequest(tr_torrent const* torrent, tr_peer const* peer, tr_block_index_t block);
|
||||
|
||||
|
|
|
@ -1311,9 +1311,8 @@ static void parseUtPex(tr_peerMsgsImpl* msgs, uint32_t msglen, struct evbuffer*
|
|||
tr_peerIoReadBytes(msgs->io, inbuf, tmp, msglen);
|
||||
|
||||
tr_variant val;
|
||||
bool const loaded = tr_variantFromBuf(&val, TR_VARIANT_PARSE_BENC | TR_VARIANT_PARSE_INPLACE, { tmp, msglen });
|
||||
|
||||
if (loaded)
|
||||
if (tr_variantFromBuf(&val, TR_VARIANT_PARSE_BENC | TR_VARIANT_PARSE_INPLACE, { tmp, msglen }))
|
||||
{
|
||||
uint8_t const* added = nullptr;
|
||||
auto added_len = size_t{};
|
||||
|
|
|
@ -460,8 +460,7 @@ std::optional<tr_quark> tr_quark_lookup(std::string_view key)
|
|||
|
||||
tr_quark tr_quark_new(std::string_view str)
|
||||
{
|
||||
auto const prior = tr_quark_lookup(str);
|
||||
if (prior)
|
||||
if (auto const prior = tr_quark_lookup(str); prior)
|
||||
{
|
||||
return *prior;
|
||||
}
|
||||
|
|
|
@ -221,7 +221,7 @@ static uint64_t loadFilePriorities(tr_variant* dict, tr_torrent* tor)
|
|||
auto priority = int64_t{};
|
||||
if (tr_variantGetInt(tr_variantListChild(list, i), &priority))
|
||||
{
|
||||
tor->setFilePriority(i, priority);
|
||||
tor->setFilePriority(i, tr_priority_t(priority));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -728,8 +728,8 @@ static uint64_t loadFromFile(tr_torrent* tor, uint64_t fieldsToLoad, bool* didRe
|
|||
}
|
||||
|
||||
std::string const filename = getResumeFilename(tor, TR_METAINFO_BASENAME_HASH);
|
||||
auto buf = std::vector<char>{};
|
||||
if (!tr_loadFile(buf, filename.c_str(), &error) ||
|
||||
|
||||
if (auto buf = std::vector<char>{}; !tr_loadFile(buf, filename.c_str(), &error) ||
|
||||
!tr_variantFromBuf(
|
||||
&top,
|
||||
TR_VARIANT_PARSE_BENC | TR_VARIANT_PARSE_INPLACE,
|
||||
|
|
|
@ -982,14 +982,13 @@ static char const* setLabels(tr_torrent* tor, tr_variant* list)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
static char const* setFilePriorities(tr_torrent* tor, int priority, tr_variant* list)
|
||||
static char const* setFilePriorities(tr_torrent* tor, tr_priority_t priority, tr_variant* list)
|
||||
{
|
||||
char const* errmsg = nullptr;
|
||||
auto files = std::vector<tr_file_index_t>{};
|
||||
files.reserve(tr_torrentFileCount(tor));
|
||||
|
||||
size_t const n = tr_variantListSize(list);
|
||||
if (n != 0)
|
||||
if (size_t const n = tr_variantListSize(list); n != 0)
|
||||
{
|
||||
for (size_t i = 0; i < n; ++i)
|
||||
{
|
||||
|
@ -998,7 +997,7 @@ static char const* setFilePriorities(tr_torrent* tor, int priority, tr_variant*
|
|||
{
|
||||
if (0 <= tmp && tmp < tor->info.fileCount)
|
||||
{
|
||||
files.push_back(tmp);
|
||||
files.push_back(tr_file_index_t(tmp));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2521,7 +2520,7 @@ void tr_rpc_request_exec_json(
|
|||
tr_rpc_response_func callback,
|
||||
void* callback_user_data)
|
||||
{
|
||||
tr_variant* const mutable_request = const_cast<tr_variant*>(request);
|
||||
auto* const mutable_request = const_cast<tr_variant*>(request);
|
||||
tr_variant* args_in = tr_variantDictFind(mutable_request, TR_KEY_arguments);
|
||||
char const* result = nullptr;
|
||||
|
||||
|
|
|
@ -112,8 +112,7 @@ struct CaseInsensitiveStringCompare // case-insensitive string compare
|
|||
auto const alen = std::size(a);
|
||||
auto const blen = std::size(b);
|
||||
|
||||
auto i = evutil_ascii_strncasecmp(std::data(a), std::data(b), std::min(alen, blen));
|
||||
if (i != 0)
|
||||
if (auto i = evutil_ascii_strncasecmp(std::data(a), std::data(b), std::min(alen, blen)); i != 0)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
|
|
|
@ -761,6 +761,7 @@ bool tr_utf8_validate(std::string_view sv, char const** good_end)
|
|||
auto const* begin = std::data(sv);
|
||||
auto const* const end = begin + std::size(sv);
|
||||
auto const* walk = begin;
|
||||
auto all_good = false;
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -768,9 +769,12 @@ bool tr_utf8_validate(std::string_view sv, char const** good_end)
|
|||
{
|
||||
utf8::next(walk, end);
|
||||
}
|
||||
|
||||
all_good = true;
|
||||
}
|
||||
catch (utf8::exception&)
|
||||
catch (utf8::exception const&)
|
||||
{
|
||||
all_good = false;
|
||||
}
|
||||
|
||||
if (good_end != nullptr)
|
||||
|
@ -778,7 +782,7 @@ bool tr_utf8_validate(std::string_view sv, char const** good_end)
|
|||
*good_end = walk;
|
||||
}
|
||||
|
||||
return walk == end;
|
||||
return all_good;
|
||||
}
|
||||
|
||||
static char* strip_non_utf8(std::string_view sv)
|
||||
|
|
|
@ -231,7 +231,7 @@ static std::string_view extract_escaped_string(char const* in, size_t in_len, st
|
|||
auto const it = utf8::append(val, std::data(buf8));
|
||||
evbuffer_add(buf, std::data(buf8), it - std::data(buf8));
|
||||
}
|
||||
catch (utf8::exception&)
|
||||
catch (utf8::exception const&)
|
||||
{ // invalid codepoint
|
||||
evbuffer_add(buf, "?", 1);
|
||||
}
|
||||
|
@ -588,7 +588,7 @@ static void jsonStringFunc(tr_variant const* val, void* vdata)
|
|||
outwalk += tr_snprintf(outwalk, outend - outwalk, "\\u%04x", uch32);
|
||||
sv.remove_prefix(walk8 - begin8 - 1);
|
||||
}
|
||||
catch (utf8::exception&)
|
||||
catch (utf8::exception const&)
|
||||
{
|
||||
*outwalk++ = '?';
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue