refactor: fix recent sonarcloud warnings (#3593)
This commit is contained in:
parent
868fc1ab78
commit
90f08f4fa1
|
@ -26,6 +26,7 @@
|
||||||
#include <libtransmission/torrent-metainfo.h>
|
#include <libtransmission/torrent-metainfo.h>
|
||||||
#include <libtransmission/tr-assert.h>
|
#include <libtransmission/tr-assert.h>
|
||||||
#include <libtransmission/utils.h> // tr_free(), tr_time()
|
#include <libtransmission/utils.h> // tr_free(), tr_time()
|
||||||
|
#include <libtransmission/web-utils.h> // tr_urlIsValid()
|
||||||
#include <libtransmission/variant.h>
|
#include <libtransmission/variant.h>
|
||||||
|
|
||||||
#include "Actions.h"
|
#include "Actions.h"
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include "torrent-metainfo.h"
|
#include "torrent-metainfo.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "variant.h"
|
#include "variant.h"
|
||||||
|
#include "web-utils.h"
|
||||||
|
|
||||||
using namespace std::literals;
|
using namespace std::literals;
|
||||||
|
|
||||||
|
|
|
@ -15,9 +15,9 @@
|
||||||
|
|
||||||
#include "quark.h"
|
#include "quark.h"
|
||||||
#include "interned-string.h"
|
#include "interned-string.h"
|
||||||
#include "web-utils.h"
|
|
||||||
|
|
||||||
struct tr_error;
|
struct tr_error;
|
||||||
|
struct tr_url_parsed_t;
|
||||||
|
|
||||||
class tr_announce_list
|
class tr_announce_list
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,7 +21,8 @@
|
||||||
#include "interned-string.h"
|
#include "interned-string.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "peer-mgr.h" // tr_pex
|
#include "peer-mgr.h" // tr_pex
|
||||||
#include "web-utils.h"
|
|
||||||
|
struct tr_url_parsed_t;
|
||||||
|
|
||||||
/***
|
/***
|
||||||
**** SCRAPE
|
**** SCRAPE
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
// 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> // std::find_if()
|
#include <algorithm> // for std::find_if()
|
||||||
#include <cerrno> /* errno, EAFNOSUPPORT */
|
#include <cerrno> // for errno, EAFNOSUPPORT
|
||||||
#include <cstring> /* memset() */
|
#include <cstring> // for memset()
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
|
@ -180,8 +180,7 @@ constexpr std::string_view charint(char ch)
|
||||||
int strint(char const* pch, int span, int base = 10)
|
int strint(char const* pch, int span, int base = 10)
|
||||||
{
|
{
|
||||||
auto sv = std::string_view{ pch, static_cast<size_t>(span) };
|
auto sv = std::string_view{ pch, static_cast<size_t>(span) };
|
||||||
auto const num = tr_parseNum<int>(sv, base);
|
return tr_parseNum<int>(sv, base).value_or(0);
|
||||||
return num ? *num : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr std::string_view getMnemonicEnd(uint8_t ch)
|
constexpr std::string_view getMnemonicEnd(uint8_t ch)
|
||||||
|
|
|
@ -96,18 +96,18 @@ class ShaHelper
|
||||||
public:
|
public:
|
||||||
using EvpFunc = decltype((EVP_sha1));
|
using EvpFunc = decltype((EVP_sha1));
|
||||||
|
|
||||||
ShaHelper(EvpFunc evp_func)
|
explicit ShaHelper(EvpFunc evp_func)
|
||||||
: evp_func_{ evp_func }
|
: evp_func_{ evp_func }
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear()
|
void clear() const
|
||||||
{
|
{
|
||||||
EVP_DigestInit_ex(handle_.get(), evp_func_(), nullptr);
|
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)
|
if (data_length != 0U)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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);
|
TR_ASSERT(handle != TR_BAD_SYS_FILE);
|
||||||
|
|
||||||
struct stat sb;
|
if (struct stat sb; fstat(handle, &sb) != -1)
|
||||||
|
|
||||||
if (fstat(handle, &sb) != -1)
|
|
||||||
{
|
{
|
||||||
return stat_to_sys_path_info(sb);
|
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(address != nullptr);
|
||||||
TR_ASSERT(size > 0);
|
TR_ASSERT(size > 0);
|
||||||
|
|
||||||
bool const ret = munmap((void*)address, size) != -1;
|
bool const ret = munmap(const_cast<void*>(address), size) != -1;
|
||||||
|
|
||||||
if (!ret)
|
if (!ret)
|
||||||
{
|
{
|
||||||
|
@ -1195,7 +1193,7 @@ std::string tr_sys_dir_get_current(tr_error** error)
|
||||||
|
|
||||||
for (;;)
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "tr-macros.h"
|
#include "tr-macros.h"
|
||||||
#include "tr-strbuf.h"
|
|
||||||
|
|
||||||
struct tr_error;
|
struct tr_error;
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
class tr_metainfo_builder
|
class tr_metainfo_builder
|
||||||
{
|
{
|
||||||
public:
|
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&&) = delete;
|
||||||
tr_metainfo_builder(tr_metainfo_builder const&) = delete;
|
tr_metainfo_builder(tr_metainfo_builder const&) = delete;
|
||||||
|
|
|
@ -335,9 +335,7 @@ struct tr_peer_socket tr_netOpenPeerSocket(tr_session* session, tr_address const
|
||||||
#endif
|
#endif
|
||||||
sockerrno != EINPROGRESS)
|
sockerrno != EINPROGRESS)
|
||||||
{
|
{
|
||||||
int const tmperrno = sockerrno;
|
if (auto const tmperrno = sockerrno; (tmperrno != ENETUNREACH && tmperrno != EHOSTUNREACH) || addr->isIPv4())
|
||||||
|
|
||||||
if ((tmperrno != ENETUNREACH && tmperrno != EHOSTUNREACH) || addr->isIPv4())
|
|
||||||
{
|
{
|
||||||
tr_logAddWarn(fmt::format(
|
tr_logAddWarn(fmt::format(
|
||||||
_("Couldn't connect socket {socket} to {address}:{port}: {error} ({error_code})"),
|
_("Couldn't connect socket {socket} to {address}:{port}: {error} ({error_code})"),
|
||||||
|
|
|
@ -46,6 +46,7 @@
|
||||||
#include "trevent.h"
|
#include "trevent.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "variant.h"
|
#include "variant.h"
|
||||||
|
#include "web-utils.h"
|
||||||
#include "web.h"
|
#include "web.h"
|
||||||
|
|
||||||
using namespace std::literals;
|
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* key = "Accept-Encoding";
|
||||||
char const* encoding = evhttp_find_header(req->input_headers, key);
|
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));
|
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>{};
|
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());
|
send_simple_response(req, HTTP_NOTFOUND, fmt::format("{} ({})", filename, error->message).c_str());
|
||||||
tr_error_free(error);
|
tr_error_free(error);
|
||||||
|
|
|
@ -11,10 +11,10 @@
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdlib> // atoi()
|
#include <cstdlib> // atoi()
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <iterator> // std::back_inserter
|
#include <iterator> // for std::back_inserter
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <numeric> // std::accumulate()
|
#include <numeric> // for std::accumulate()
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
@ -45,7 +45,6 @@
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "peer-io.h"
|
#include "peer-io.h"
|
||||||
#include "peer-mgr.h"
|
#include "peer-mgr.h"
|
||||||
#include "platform-quota.h" /* tr_device_info_free() */
|
|
||||||
#include "port-forwarding.h"
|
#include "port-forwarding.h"
|
||||||
#include "rpc-server.h"
|
#include "rpc-server.h"
|
||||||
#include "session-id.h"
|
#include "session-id.h"
|
||||||
|
|
|
@ -62,7 +62,7 @@ struct tr_fdInfo;
|
||||||
|
|
||||||
struct tr_bindinfo
|
struct tr_bindinfo
|
||||||
{
|
{
|
||||||
tr_bindinfo(tr_address addr)
|
explicit tr_bindinfo(tr_address addr)
|
||||||
: addr_{ std::move(addr) }
|
: addr_{ std::move(addr) }
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,14 +23,12 @@
|
||||||
#include "bitfield.h"
|
#include "bitfield.h"
|
||||||
#include "block-info.h"
|
#include "block-info.h"
|
||||||
#include "completion.h"
|
#include "completion.h"
|
||||||
#include "file.h"
|
|
||||||
#include "file-piece-map.h"
|
#include "file-piece-map.h"
|
||||||
#include "interned-string.h"
|
#include "interned-string.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "session.h"
|
#include "session.h"
|
||||||
#include "torrent-metainfo.h"
|
#include "torrent-metainfo.h"
|
||||||
#include "tr-macros.h"
|
#include "tr-macros.h"
|
||||||
#include "tr-strbuf.h"
|
|
||||||
|
|
||||||
class tr_swarm;
|
class tr_swarm;
|
||||||
struct tr_error;
|
struct tr_error;
|
||||||
|
|
|
@ -11,8 +11,9 @@
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include <fmt/format.h>
|
||||||
|
|
||||||
#include "tr-macros.h" // tr_sha1_digest_t
|
#include "tr-macros.h" // tr_sha1_digest_t
|
||||||
#include "tr-strbuf.h" // tr_urlbuf
|
|
||||||
|
|
||||||
struct evbuffer;
|
struct evbuffer;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue