mirror of
https://github.com/transmission/transmission
synced 2025-02-24 15:10:39 +00:00
fix: sonarcloud (#2837)
* fix: rename variable to avoid shadow warning w/UTP * fix: add default dtor for tr_strbuf * fix: implicit conversion may lose precision * fix: use init-statement to reduce variable scope * fix: implicit conversion may lose precision * fix: extract the assignment from this expression * fix: use init-statement to reduce variable scope * fix: use init-statement to reduce variable scope * fix: do not mix public and private data members * fix: add a condition to cv.wait call * fix: do not throw uncaught exceptions in destructor
This commit is contained in:
parent
2f677aebb0
commit
4177e286a1
11 changed files with 21 additions and 24 deletions
|
@ -147,7 +147,7 @@ if(WIN32)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
find_package(Fmt)
|
find_package(Fmt)
|
||||||
add_definitions(-DFMT_HEADER_ONLY)
|
add_definitions(-DFMT_HEADER_ONLY -DFMT_EXCEPTIONS=0)
|
||||||
include_directories(SYSTEM ${LIBFMT_INCLUDE_DIRS})
|
include_directories(SYSTEM ${LIBFMT_INCLUDE_DIRS})
|
||||||
|
|
||||||
find_package(UtfCpp)
|
find_package(UtfCpp)
|
||||||
|
|
|
@ -158,8 +158,8 @@ template<>
|
||||||
struct fmt::formatter<tr_interned_string> : formatter<std::string_view>
|
struct fmt::formatter<tr_interned_string> : formatter<std::string_view>
|
||||||
{
|
{
|
||||||
template<typename FormatContext>
|
template<typename FormatContext>
|
||||||
constexpr auto format(tr_interned_string const& str, FormatContext& ctx) const
|
constexpr auto format(tr_interned_string const& is, FormatContext& ctx) const
|
||||||
{
|
{
|
||||||
return formatter<std::string_view>::format(str.sv(), ctx);
|
return formatter<std::string_view>::format(is.sv(), ctx);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -51,7 +51,6 @@ public:
|
||||||
|
|
||||||
int queue_length_ = 0;
|
int queue_length_ = 0;
|
||||||
|
|
||||||
private:
|
|
||||||
std::recursive_mutex message_mutex_;
|
std::recursive_mutex message_mutex_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -424,8 +424,7 @@ static void utp_on_read(void* vio, unsigned char const* buf, size_t buflen)
|
||||||
|
|
||||||
TR_ASSERT(tr_isPeerIo(io));
|
TR_ASSERT(tr_isPeerIo(io));
|
||||||
|
|
||||||
int rc = evbuffer_add(io->inbuf, buf, buflen);
|
if (auto const rc = evbuffer_add(io->inbuf, buf, buflen); rc < 0)
|
||||||
if (rc < 0)
|
|
||||||
{
|
{
|
||||||
tr_logAddWarn(_("Couldn't write to peer"));
|
tr_logAddWarn(_("Couldn't write to peer"));
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -140,13 +140,12 @@ static void saveGroup(tr_variant* dict, tr_torrent const* tor)
|
||||||
|
|
||||||
static auto loadGroup(tr_variant* dict, tr_torrent* tor)
|
static auto loadGroup(tr_variant* dict, tr_torrent* tor)
|
||||||
{
|
{
|
||||||
std::string_view groupName;
|
if (std::string_view groupName; tr_variantDictFindStrView(dict, TR_KEY_group, &groupName) && !groupName.empty())
|
||||||
|
|
||||||
if (tr_variantDictFindStrView(dict, TR_KEY_group, &groupName) && !groupName.empty())
|
|
||||||
{
|
{
|
||||||
tor->setGroup(groupName);
|
tor->setGroup(groupName);
|
||||||
return tr_resume::Group;
|
return tr_resume::Group;
|
||||||
}
|
}
|
||||||
|
|
||||||
return tr_resume::fields_t{};
|
return tr_resume::fields_t{};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2890,8 +2890,10 @@ static void bandwidthGroupRead(tr_session* session, std::string_view config_dir)
|
||||||
auto idx = size_t{ 0 };
|
auto idx = size_t{ 0 };
|
||||||
auto key = tr_quark{};
|
auto key = tr_quark{};
|
||||||
tr_variant* dict = nullptr;
|
tr_variant* dict = nullptr;
|
||||||
while (tr_variantDictChild(&groups_dict, idx++, &key, &dict))
|
while (tr_variantDictChild(&groups_dict, idx, &key, &dict))
|
||||||
{
|
{
|
||||||
|
++idx;
|
||||||
|
|
||||||
auto name = tr_interned_string(key);
|
auto name = tr_interned_string(key);
|
||||||
auto& group = session->getBandwidthGroup(name);
|
auto& group = session->getBandwidthGroup(name);
|
||||||
|
|
||||||
|
|
|
@ -179,8 +179,8 @@ static void dht_boostrap_from_file(tr_session* session)
|
||||||
static void dht_bootstrap(void* closure)
|
static void dht_bootstrap(void* closure)
|
||||||
{
|
{
|
||||||
auto* const cl = static_cast<struct bootstrap_closure*>(closure);
|
auto* const cl = static_cast<struct bootstrap_closure*>(closure);
|
||||||
int const num = cl->len / 6;
|
auto const num = cl->len / 6;
|
||||||
int const num6 = cl->len6 / 18;
|
auto const num6 = cl->len6 / 18;
|
||||||
|
|
||||||
if (session_ != cl->session)
|
if (session_ != cl->session)
|
||||||
{
|
{
|
||||||
|
@ -197,7 +197,7 @@ static void dht_bootstrap(void* closure)
|
||||||
tr_logAddDebug(fmt::format("Bootstrapping from {} IPv6 nodes", num6));
|
tr_logAddDebug(fmt::format("Bootstrapping from {} IPv6 nodes", num6));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < std::max(num, num6); ++i)
|
for (size_t i = 0; i < std::max(num, num6); ++i)
|
||||||
{
|
{
|
||||||
if (i < num && !bootstrap_done(cl->session, AF_INET))
|
if (i < num && !bootstrap_done(cl->session, AF_INET))
|
||||||
{
|
{
|
||||||
|
@ -228,7 +228,7 @@ static void dht_bootstrap(void* closure)
|
||||||
/* Our DHT code is able to take up to 9 nodes in a row without
|
/* Our DHT code is able to take up to 9 nodes in a row without
|
||||||
dropping any. After that, it takes some time to split buckets.
|
dropping any. After that, it takes some time to split buckets.
|
||||||
So ping the first 8 nodes quickly, then slow down. */
|
So ping the first 8 nodes quickly, then slow down. */
|
||||||
if (i < 8)
|
if (i < 8U)
|
||||||
{
|
{
|
||||||
nap(2);
|
nap(2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ public:
|
||||||
using const_reference = const Char&;
|
using const_reference = const Char&;
|
||||||
|
|
||||||
tr_strbuf() = default;
|
tr_strbuf() = default;
|
||||||
|
~tr_strbuf() = default;
|
||||||
tr_strbuf(tr_strbuf const& other) = delete;
|
tr_strbuf(tr_strbuf const& other) = delete;
|
||||||
tr_strbuf& operator=(tr_strbuf const& other) = delete;
|
tr_strbuf& operator=(tr_strbuf const& other) = delete;
|
||||||
|
|
||||||
|
@ -35,14 +36,14 @@ public:
|
||||||
buffer_ = std::move(other.buffer_);
|
buffer_ = std::move(other.buffer_);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& operator=(tr_strbuf&& other) noexcept
|
tr_strbuf& operator=(tr_strbuf&& other) noexcept
|
||||||
{
|
{
|
||||||
buffer_ = std::move(other.buffer_);
|
buffer_ = std::move(other.buffer_);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
tr_strbuf(Args const&... args)
|
explicit tr_strbuf(Args const&... args)
|
||||||
{
|
{
|
||||||
append(args...);
|
append(args...);
|
||||||
}
|
}
|
||||||
|
|
|
@ -193,9 +193,7 @@ static void libeventThreadFunc(tr_event_handle* events)
|
||||||
|
|
||||||
// tell the thread that's waiting in tr_eventInit()
|
// tell the thread that's waiting in tr_eventInit()
|
||||||
// that this thread is ready for business
|
// that this thread is ready for business
|
||||||
events->work_queue_mutex.lock();
|
|
||||||
events->work_queue_cv.notify_one();
|
events->work_queue_cv.notify_one();
|
||||||
events->work_queue_mutex.unlock();
|
|
||||||
|
|
||||||
// loop until `tr_eventClose()` kills the loop
|
// loop until `tr_eventClose()` kills the loop
|
||||||
event_base_loop(base, EVLOOP_NO_EXIT_ON_EMPTY);
|
event_base_loop(base, EVLOOP_NO_EXIT_ON_EMPTY);
|
||||||
|
@ -226,7 +224,7 @@ void tr_eventInit(tr_session* session)
|
||||||
events->thread_id = thread.get_id();
|
events->thread_id = thread.get_id();
|
||||||
thread.detach();
|
thread.detach();
|
||||||
// wait until the libevent thread is running
|
// wait until the libevent thread is running
|
||||||
events->work_queue_cv.wait(lock);
|
events->work_queue_cv.wait(lock, [session] { return session->events != nullptr; });
|
||||||
}
|
}
|
||||||
|
|
||||||
void tr_eventClose(tr_session* session)
|
void tr_eventClose(tr_session* session)
|
||||||
|
|
|
@ -94,12 +94,12 @@ struct tr_url_query_view
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename OutputIt>
|
template<typename OutputIt>
|
||||||
void tr_http_escape(OutputIt out, std::string_view str, bool escape_reserved)
|
void tr_http_escape(OutputIt out, std::string_view in, bool escape_reserved)
|
||||||
{
|
{
|
||||||
auto constexpr ReservedChars = std::string_view{ "!*'();:@&=+$,/?%#[]" };
|
auto constexpr ReservedChars = std::string_view{ "!*'();:@&=+$,/?%#[]" };
|
||||||
auto constexpr UnescapedChars = std::string_view{ "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_.~" };
|
auto constexpr UnescapedChars = std::string_view{ "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_.~" };
|
||||||
|
|
||||||
for (auto const& ch : str)
|
for (auto const& ch : in)
|
||||||
{
|
{
|
||||||
if (tr_strvContains(UnescapedChars, ch) || (tr_strvContains(ReservedChars, ch) && !escape_reserved))
|
if (tr_strvContains(UnescapedChars, ch) || (tr_strvContains(ReservedChars, ch) && !escape_reserved))
|
||||||
{
|
{
|
||||||
|
|
|
@ -560,8 +560,7 @@ static bool UseSSL = false;
|
||||||
|
|
||||||
static std::string getEncodedMetainfo(std::string_view filename)
|
static std::string getEncodedMetainfo(std::string_view filename)
|
||||||
{
|
{
|
||||||
auto contents = std::vector<char>{};
|
if (auto contents = std::vector<char>{}; tr_loadFile(filename, contents))
|
||||||
if (tr_loadFile(filename, contents))
|
|
||||||
{
|
{
|
||||||
return tr_base64_encode({ std::data(contents), std::size(contents) });
|
return tr_base64_encode({ std::data(contents), std::size(contents) });
|
||||||
}
|
}
|
||||||
|
@ -2020,7 +2019,7 @@ static void printGroups(tr_variant* top)
|
||||||
|
|
||||||
if (tr_variantDictFindDict(top, TR_KEY_arguments, &args) && tr_variantDictFindList(args, TR_KEY_group, &groups))
|
if (tr_variantDictFindDict(top, TR_KEY_arguments, &args) && tr_variantDictFindList(args, TR_KEY_group, &groups))
|
||||||
{
|
{
|
||||||
for (int i = 0, n = tr_variantListSize(groups); i < n; ++i)
|
for (size_t i = 0, n = tr_variantListSize(groups); i < n; ++i)
|
||||||
{
|
{
|
||||||
tr_variant* group = tr_variantListChild(groups, i);
|
tr_variant* group = tr_variantListChild(groups, i);
|
||||||
std::string_view name;
|
std::string_view name;
|
||||||
|
|
Loading…
Reference in a new issue