1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-01-31 03:12:44 +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:
Charles Kerr 2022-03-29 05:57:04 -05:00 committed by GitHub
parent 2f677aebb0
commit 4177e286a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 21 additions and 24 deletions

View file

@ -147,7 +147,7 @@ if(WIN32)
endif()
find_package(Fmt)
add_definitions(-DFMT_HEADER_ONLY)
add_definitions(-DFMT_HEADER_ONLY -DFMT_EXCEPTIONS=0)
include_directories(SYSTEM ${LIBFMT_INCLUDE_DIRS})
find_package(UtfCpp)

View file

@ -158,8 +158,8 @@ template<>
struct fmt::formatter<tr_interned_string> : formatter<std::string_view>
{
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);
}
};

View file

@ -51,7 +51,6 @@ public:
int queue_length_ = 0;
private:
std::recursive_mutex message_mutex_;
};

View file

@ -424,8 +424,7 @@ static void utp_on_read(void* vio, unsigned char const* buf, size_t buflen)
TR_ASSERT(tr_isPeerIo(io));
int rc = evbuffer_add(io->inbuf, buf, buflen);
if (rc < 0)
if (auto const rc = evbuffer_add(io->inbuf, buf, buflen); rc < 0)
{
tr_logAddWarn(_("Couldn't write to peer"));
return;

View file

@ -140,13 +140,12 @@ static void saveGroup(tr_variant* dict, tr_torrent const* tor)
static auto loadGroup(tr_variant* dict, tr_torrent* tor)
{
std::string_view groupName;
if (tr_variantDictFindStrView(dict, TR_KEY_group, &groupName) && !groupName.empty())
if (std::string_view groupName; tr_variantDictFindStrView(dict, TR_KEY_group, &groupName) && !groupName.empty())
{
tor->setGroup(groupName);
return tr_resume::Group;
}
return tr_resume::fields_t{};
}

View file

@ -2890,8 +2890,10 @@ static void bandwidthGroupRead(tr_session* session, std::string_view config_dir)
auto idx = size_t{ 0 };
auto key = tr_quark{};
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& group = session->getBandwidthGroup(name);

View file

@ -179,8 +179,8 @@ static void dht_boostrap_from_file(tr_session* session)
static void dht_bootstrap(void* closure)
{
auto* const cl = static_cast<struct bootstrap_closure*>(closure);
int const num = cl->len / 6;
int const num6 = cl->len6 / 18;
auto const num = cl->len / 6;
auto const num6 = cl->len6 / 18;
if (session_ != cl->session)
{
@ -197,7 +197,7 @@ static void dht_bootstrap(void* closure)
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))
{
@ -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
dropping any. After that, it takes some time to split buckets.
So ping the first 8 nodes quickly, then slow down. */
if (i < 8)
if (i < 8U)
{
nap(2);
}

View file

@ -27,6 +27,7 @@ public:
using const_reference = const Char&;
tr_strbuf() = default;
~tr_strbuf() = default;
tr_strbuf(tr_strbuf const& other) = delete;
tr_strbuf& operator=(tr_strbuf const& other) = delete;
@ -35,14 +36,14 @@ public:
buffer_ = std::move(other.buffer_);
}
auto& operator=(tr_strbuf&& other) noexcept
tr_strbuf& operator=(tr_strbuf&& other) noexcept
{
buffer_ = std::move(other.buffer_);
return *this;
}
template<typename... Args>
tr_strbuf(Args const&... args)
explicit tr_strbuf(Args const&... args)
{
append(args...);
}

View file

@ -193,9 +193,7 @@ static void libeventThreadFunc(tr_event_handle* events)
// tell the thread that's waiting in tr_eventInit()
// that this thread is ready for business
events->work_queue_mutex.lock();
events->work_queue_cv.notify_one();
events->work_queue_mutex.unlock();
// loop until `tr_eventClose()` kills the loop
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();
thread.detach();
// 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)

View file

@ -94,12 +94,12 @@ struct tr_url_query_view
};
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 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))
{

View file

@ -560,8 +560,7 @@ static bool UseSSL = false;
static std::string getEncodedMetainfo(std::string_view filename)
{
auto contents = std::vector<char>{};
if (tr_loadFile(filename, contents))
if (auto contents = std::vector<char>{}; tr_loadFile(filename, 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))
{
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);
std::string_view name;