refactor: fix recent sonarcloud warnings (#3593)

This commit is contained in:
Charles Kerr 2022-08-05 20:37:21 -05:00 committed by GitHub
parent 868fc1ab78
commit 90f08f4fa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 26 additions and 31 deletions

View File

@ -26,6 +26,7 @@
#include <libtransmission/torrent-metainfo.h>
#include <libtransmission/tr-assert.h>
#include <libtransmission/utils.h> // tr_free(), tr_time()
#include <libtransmission/web-utils.h> // tr_urlIsValid()
#include <libtransmission/variant.h>
#include "Actions.h"

View File

@ -15,6 +15,7 @@
#include "torrent-metainfo.h"
#include "utils.h"
#include "variant.h"
#include "web-utils.h"
using namespace std::literals;

View File

@ -15,9 +15,9 @@
#include "quark.h"
#include "interned-string.h"
#include "web-utils.h"
struct tr_error;
struct tr_url_parsed_t;
class tr_announce_list
{

View File

@ -21,7 +21,8 @@
#include "interned-string.h"
#include "net.h"
#include "peer-mgr.h" // tr_pex
#include "web-utils.h"
struct tr_url_parsed_t;
/***
**** SCRAPE

View File

@ -3,9 +3,9 @@
// or any future license endorsed by Mnemosyne LLC.
// License text can be found in the licenses/ folder.
#include <algorithm> // std::find_if()
#include <cerrno> /* errno, EAFNOSUPPORT */
#include <cstring> /* memset() */
#include <algorithm> // for std::find_if()
#include <cerrno> // for errno, EAFNOSUPPORT
#include <cstring> // for memset()
#include <ctime>
#include <list>
#include <memory>

View File

@ -180,8 +180,7 @@ constexpr std::string_view charint(char ch)
int strint(char const* pch, int span, int base = 10)
{
auto sv = std::string_view{ pch, static_cast<size_t>(span) };
auto const num = tr_parseNum<int>(sv, base);
return num ? *num : 0;
return tr_parseNum<int>(sv, base).value_or(0);
}
constexpr std::string_view getMnemonicEnd(uint8_t ch)

View File

@ -96,18 +96,18 @@ class ShaHelper
public:
using EvpFunc = decltype((EVP_sha1));
ShaHelper(EvpFunc evp_func)
explicit ShaHelper(EvpFunc evp_func)
: evp_func_{ evp_func }
{
clear();
}
void clear()
void clear() const
{
EVP_DigestInit_ex(handle_.get(), evp_func_(), nullptr);
}
void update(void const* data, size_t data_length)
void update(void const* data, size_t data_length) const
{
if (data_length != 0U)
{

View File

@ -692,9 +692,7 @@ std::optional<tr_sys_path_info> tr_sys_file_get_info(tr_sys_file_t handle, tr_er
{
TR_ASSERT(handle != TR_BAD_SYS_FILE);
struct stat sb;
if (fstat(handle, &sb) != -1)
if (struct stat sb; fstat(handle, &sb) != -1)
{
return stat_to_sys_path_info(sb);
}
@ -1094,7 +1092,7 @@ bool tr_sys_file_unmap(void const* address, uint64_t size, tr_error** error)
TR_ASSERT(address != nullptr);
TR_ASSERT(size > 0);
bool const ret = munmap((void*)address, size) != -1;
bool const ret = munmap(const_cast<void*>(address), size) != -1;
if (!ret)
{
@ -1195,7 +1193,7 @@ std::string tr_sys_dir_get_current(tr_error** error)
for (;;)
{
if (char* ret = getcwd(std::data(buf), std::size(buf)); ret != nullptr)
if (char* const ret = getcwd(std::data(buf), std::size(buf)); ret != nullptr)
{
return ret;
}

View File

@ -17,7 +17,6 @@
#endif
#include "tr-macros.h"
#include "tr-strbuf.h"
struct tr_error;

View File

@ -24,7 +24,7 @@
class tr_metainfo_builder
{
public:
tr_metainfo_builder(std::string_view single_file_or_parent_directory);
explicit tr_metainfo_builder(std::string_view single_file_or_parent_directory);
tr_metainfo_builder(tr_metainfo_builder&&) = delete;
tr_metainfo_builder(tr_metainfo_builder const&) = delete;

View File

@ -335,9 +335,7 @@ struct tr_peer_socket tr_netOpenPeerSocket(tr_session* session, tr_address const
#endif
sockerrno != EINPROGRESS)
{
int const tmperrno = sockerrno;
if ((tmperrno != ENETUNREACH && tmperrno != EHOSTUNREACH) || addr->isIPv4())
if (auto const tmperrno = sockerrno; (tmperrno != ENETUNREACH && tmperrno != EHOSTUNREACH) || addr->isIPv4())
{
tr_logAddWarn(fmt::format(
_("Couldn't connect socket {socket} to {address}:{port}: {error} ({error_code})"),

View File

@ -46,6 +46,7 @@
#include "trevent.h"
#include "utils.h"
#include "variant.h"
#include "web-utils.h"
#include "web.h"
using namespace std::literals;
@ -168,9 +169,8 @@ static evbuffer* make_response(struct evhttp_request* req, tr_rpc_server* server
char const* key = "Accept-Encoding";
char const* encoding = evhttp_find_header(req->input_headers, key);
bool const do_compress = encoding != nullptr && tr_strvContains(encoding, "gzip"sv);
if (!do_compress)
if (bool const do_compress = encoding != nullptr && tr_strvContains(encoding, "gzip"sv); !do_compress)
{
evbuffer_add(out, std::data(content), std::size(content));
}
@ -220,8 +220,8 @@ static void serve_file(struct evhttp_request* req, tr_rpc_server* server, std::s
}
auto content = std::vector<char>{};
tr_error* error = nullptr;
if (!tr_loadFile(filename, content, &error))
if (tr_error* error = nullptr; !tr_loadFile(filename, content, &error))
{
send_simple_response(req, HTTP_NOTFOUND, fmt::format("{} ({})", filename, error->message).c_str());
tr_error_free(error);

View File

@ -11,10 +11,10 @@
#include <cstdint>
#include <cstdlib> // atoi()
#include <ctime>
#include <iterator> // std::back_inserter
#include <iterator> // for std::back_inserter
#include <list>
#include <memory>
#include <numeric> // std::accumulate()
#include <numeric> // for std::accumulate()
#include <string>
#include <string_view>
#include <unordered_set>
@ -45,7 +45,6 @@
#include "net.h"
#include "peer-io.h"
#include "peer-mgr.h"
#include "platform-quota.h" /* tr_device_info_free() */
#include "port-forwarding.h"
#include "rpc-server.h"
#include "session-id.h"

View File

@ -62,7 +62,7 @@ struct tr_fdInfo;
struct tr_bindinfo
{
tr_bindinfo(tr_address addr)
explicit tr_bindinfo(tr_address addr)
: addr_{ std::move(addr) }
{
}

View File

@ -23,14 +23,12 @@
#include "bitfield.h"
#include "block-info.h"
#include "completion.h"
#include "file.h"
#include "file-piece-map.h"
#include "interned-string.h"
#include "log.h"
#include "session.h"
#include "torrent-metainfo.h"
#include "tr-macros.h"
#include "tr-strbuf.h"
class tr_swarm;
struct tr_error;

View File

@ -11,8 +11,9 @@
#include <string_view>
#include <utility>
#include <fmt/format.h>
#include "tr-macros.h" // tr_sha1_digest_t
#include "tr-strbuf.h" // tr_urlbuf
struct evbuffer;