mirror of
https://github.com/transmission/transmission
synced 2025-03-09 13:50:00 +00:00
fix: sonarcloud code smells (#2623)
* fix: make variable a pointer-to-const * fix: use init-statement to reduce variable scope * fix: implicit conversion from long to int * fix: refactor to not nest more than 3 if|for|do|while|switch statements * fix: make tr_session::setSocketTos() const * fix: use array.prototype.some instead of a for loop * refactor: use nullptr instead of NULL * fix: oops
This commit is contained in:
parent
94c7208d82
commit
d772824553
8 changed files with 17 additions and 32 deletions
|
@ -468,7 +468,7 @@ void TorrentUrlChooserDialog::onOpenURLResponse(int response, Glib::RefPtr<Sessi
|
|||
}
|
||||
else if (response == Gtk::RESPONSE_ACCEPT)
|
||||
{
|
||||
auto* const e = static_cast<Gtk::Entry*>(get_data("url-entry"));
|
||||
auto const* const e = static_cast<Gtk::Entry*>(get_data("url-entry"));
|
||||
auto const url = gtr_str_strip(e->get_text());
|
||||
|
||||
if (url.empty())
|
||||
|
|
|
@ -215,16 +215,12 @@ bool tr_magnet_metainfo::parseMagnet(std::string_view magnet_link, tr_error** er
|
|||
this->webseed_urls_.emplace_back(url_sv);
|
||||
}
|
||||
}
|
||||
else if (key == "xt"sv)
|
||||
else if (auto constexpr ValPrefix = "urn:btih:"sv; key == "xt"sv && tr_strvStartsWith(value, ValPrefix))
|
||||
{
|
||||
auto constexpr ValPrefix = "urn:btih:"sv;
|
||||
if (tr_strvStartsWith(value, ValPrefix))
|
||||
if (auto const hash = parseHash(value.substr(std::size(ValPrefix))); hash)
|
||||
{
|
||||
if (auto const hash = parseHash(value.substr(std::size(ValPrefix))); hash)
|
||||
{
|
||||
this->info_hash_ = *hash;
|
||||
got_hash = true;
|
||||
}
|
||||
this->info_hash_ = *hash;
|
||||
got_hash = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -233,7 +233,7 @@ public:
|
|||
peer_congestion_algorithm_ = algorithm;
|
||||
}
|
||||
|
||||
void setSocketTOS(tr_socket_t sock, tr_address_type type)
|
||||
void setSocketTOS(tr_socket_t sock, tr_address_type type) const
|
||||
{
|
||||
tr_netSetTOS(sock, peer_socket_tos_, type);
|
||||
}
|
||||
|
|
|
@ -315,21 +315,19 @@ std::string_view getSiteName(std::string_view host)
|
|||
}
|
||||
|
||||
// is it a registered name?
|
||||
char* lower = nullptr;
|
||||
if (PSL_SUCCESS == psl_str_to_utf8lower(szhost.c_str(), nullptr, nullptr, &lower))
|
||||
if (char* lower = nullptr; psl_str_to_utf8lower(szhost.c_str(), nullptr, nullptr, &lower) == PSL_SUCCESS)
|
||||
{
|
||||
// www.example.com -> example.com
|
||||
char const* const top = psl_registrable_domain(psl_builtin(), lower);
|
||||
if (top != nullptr)
|
||||
if (char const* const top = psl_registrable_domain(psl_builtin(), lower); top != nullptr)
|
||||
{
|
||||
host.remove_prefix(top - lower);
|
||||
}
|
||||
|
||||
psl_free_string(lower);
|
||||
}
|
||||
|
||||
// example.com -> example
|
||||
auto const dot_pos = host.find('.');
|
||||
if (dot_pos != std::string_view::npos)
|
||||
if (auto const dot_pos = host.find('.'); dot_pos != std::string_view::npos)
|
||||
{
|
||||
host = host.substr(0, dot_pos);
|
||||
}
|
||||
|
|
|
@ -302,7 +302,7 @@ static CURL* createEasy(tr_session* s, struct tr_web* web, struct tr_web_task* t
|
|||
|
||||
if (web->curl_proxy_ssl_verify)
|
||||
{
|
||||
if (web->curl_ca_bundle != NULL)
|
||||
if (web->curl_ca_bundle != nullptr)
|
||||
{
|
||||
curl_easy_setopt(e, CURLOPT_PROXY_CAINFO, web->curl_ca_bundle);
|
||||
}
|
||||
|
|
|
@ -129,8 +129,7 @@ void FaviconCache::add(QString const& sitename, QString const& url_str)
|
|||
|
||||
// Try to download a favicon if we don't have one.
|
||||
// Add a placeholder to prevent repeat downloads.
|
||||
auto const already_had_it = !pixmaps_.try_emplace(sitename).second;
|
||||
if (already_had_it)
|
||||
if (auto const already_had_it = !pixmaps_.try_emplace(sitename).second; already_had_it)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -226,9 +226,9 @@ int tr_main(int argc, char* argv[])
|
|||
b,
|
||||
options.outfile.c_str(),
|
||||
std::data(options.trackers),
|
||||
std::size(options.trackers),
|
||||
static_cast<int>(std::size(options.trackers)),
|
||||
std::data(options.webseeds),
|
||||
std::size(options.webseeds),
|
||||
static_cast<int>(std::size(options.webseeds)),
|
||||
options.comment,
|
||||
options.is_private,
|
||||
options.source);
|
||||
|
|
|
@ -393,17 +393,9 @@ export class Torrent extends EventTarget {
|
|||
|
||||
// maybe filter by labels...
|
||||
if (pass) {
|
||||
for (const l of labels) {
|
||||
let m = false;
|
||||
for (let j = 0; j < this.getLabels().length; j++) {
|
||||
if (l === this.getLabels()[j]) {
|
||||
m = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pass = pass && m;
|
||||
}
|
||||
// pass if this torrent has any of these labels
|
||||
const torrent_labels = this.getLabels();
|
||||
pass = labels.some((label) => torrent_labels.includes(label));
|
||||
}
|
||||
|
||||
// maybe filter by tracker...
|
||||
|
|
Loading…
Add table
Reference in a new issue