diff --git a/CMakeLists.txt b/CMakeLists.txt index 9aa424de8..226d1253e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/libtransmission/interned-string.h b/libtransmission/interned-string.h index 0012e9c2d..d450cde53 100644 --- a/libtransmission/interned-string.h +++ b/libtransmission/interned-string.h @@ -158,8 +158,8 @@ template<> struct fmt::formatter : formatter { template - constexpr auto format(tr_interned_string const& str, FormatContext& ctx) const + constexpr auto format(tr_interned_string const& is, FormatContext& ctx) const { - return formatter::format(str.sv(), ctx); + return formatter::format(is.sv(), ctx); } }; diff --git a/libtransmission/log.cc b/libtransmission/log.cc index c46229419..1470ea711 100644 --- a/libtransmission/log.cc +++ b/libtransmission/log.cc @@ -51,7 +51,6 @@ public: int queue_length_ = 0; -private: std::recursive_mutex message_mutex_; }; diff --git a/libtransmission/peer-io.cc b/libtransmission/peer-io.cc index 5eaedd452..b58beaf79 100644 --- a/libtransmission/peer-io.cc +++ b/libtransmission/peer-io.cc @@ -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; diff --git a/libtransmission/resume.cc b/libtransmission/resume.cc index c52a5f50b..7fed5f399 100644 --- a/libtransmission/resume.cc +++ b/libtransmission/resume.cc @@ -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{}; } diff --git a/libtransmission/session.cc b/libtransmission/session.cc index 024fd99cb..5c8fe9c02 100644 --- a/libtransmission/session.cc +++ b/libtransmission/session.cc @@ -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); diff --git a/libtransmission/tr-dht.cc b/libtransmission/tr-dht.cc index 65a16e350..61e43fb9b 100644 --- a/libtransmission/tr-dht.cc +++ b/libtransmission/tr-dht.cc @@ -179,8 +179,8 @@ static void dht_boostrap_from_file(tr_session* session) static void dht_bootstrap(void* closure) { auto* const cl = static_cast(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); } diff --git a/libtransmission/tr-strbuf.h b/libtransmission/tr-strbuf.h index 2bbec6776..99664f417 100644 --- a/libtransmission/tr-strbuf.h +++ b/libtransmission/tr-strbuf.h @@ -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 - tr_strbuf(Args const&... args) + explicit tr_strbuf(Args const&... args) { append(args...); } diff --git a/libtransmission/trevent.cc b/libtransmission/trevent.cc index 23b8e49e9..bef2d1433 100644 --- a/libtransmission/trevent.cc +++ b/libtransmission/trevent.cc @@ -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) diff --git a/libtransmission/web-utils.h b/libtransmission/web-utils.h index 60fda85ec..910a90907 100644 --- a/libtransmission/web-utils.h +++ b/libtransmission/web-utils.h @@ -94,12 +94,12 @@ struct tr_url_query_view }; template -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)) { diff --git a/utils/remote.cc b/utils/remote.cc index 3e26133c0..5ec439d3a 100644 --- a/utils/remote.cc +++ b/utils/remote.cc @@ -560,8 +560,7 @@ static bool UseSSL = false; static std::string getEncodedMetainfo(std::string_view filename) { - auto contents = std::vector{}; - if (tr_loadFile(filename, contents)) + if (auto contents = std::vector{}; 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;