From 9dd9aab9026095dd630032b66955e3e06a999bf8 Mon Sep 17 00:00:00 2001 From: Yat Ho Date: Tue, 2 Dec 2025 13:18:02 +0800 Subject: [PATCH] build: bump clang tools to 20 (#7573) * build: bump to clang-format-20 * build: bump to clang-tidy-20 * chore: revert edc59ba5d8edfb6016fad3e2da2783ef3ab0bfd3 --- .github/workflows/actions.yml | 21 +++-- CMakeLists.txt | 4 +- code_style.sh | 6 +- daemon/daemon.cc | 69 ++++++++------- gtk/.clang-tidy | 2 + gtk/Actions.cc | 7 +- gtk/Application.cc | 11 +-- gtk/DetailsDialog.cc | 11 +-- gtk/FileList.cc | 15 ++-- gtk/MainWindow.cc | 13 +-- gtk/MessageLogWindow.cc | 7 +- gtk/Notify.cc | 11 +-- gtk/Session.cc | 37 ++++---- gtk/Torrent.cc | 9 +- gtk/Utils.cc | 22 ++--- libtransmission/.clang-tidy | 4 + libtransmission/block-info.h | 4 +- libtransmission/blocklist.cc | 90 +++++++++++--------- libtransmission/crypto-utils.h | 4 +- libtransmission/favicon-cache.h | 4 +- libtransmission/ip-cache.cc | 33 ++++---- libtransmission/lru-cache.h | 2 +- libtransmission/makemeta.cc | 11 +-- libtransmission/net.cc | 56 +++++++------ libtransmission/open-files.cc | 44 +++++----- libtransmission/port-forwarding-natpmp.cc | 15 ++-- libtransmission/port-forwarding-upnp.cc | 47 ++++++----- libtransmission/port-forwarding.cc | 18 ++-- libtransmission/rpc-server.cc | 93 ++++++++++++--------- libtransmission/rpcimpl.cc | 22 ++--- libtransmission/session-id.cc | 22 ++--- libtransmission/session-thread.h | 9 +- libtransmission/session.cc | 14 ++-- libtransmission/torrent.cc | 57 +++++++------ libtransmission/torrent.h | 5 +- libtransmission/tr-dht.cc | 22 ++--- libtransmission/tr-lpd.cc | 31 +++---- libtransmission/tr-udp.cc | 66 ++++++++------- libtransmission/utils.cc | 44 +++++----- libtransmission/variant.cc | 11 +-- libtransmission/watchdir-inotify.cc | 69 ++++++++------- libtransmission/watchdir-kqueue.cc | 58 +++++++------ libtransmission/watchdir-win32.cc | 54 ++++++------ libtransmission/watchdir.cc | 22 ++--- libtransmission/web.cc | 40 +++++---- qt/.clang-tidy | 2 + qt/AboutDialog.cc | 7 +- qt/Application.cc | 7 +- tests/libtransmission/.clang-tidy | 2 + tests/libtransmission/announce-list-test.cc | 11 +-- tests/libtransmission/dht-test.cc | 10 +-- tests/libtransmission/net-test.cc | 27 +++--- tests/libtransmission/timer-test.cc | 5 +- tests/libtransmission/tr-peer-info-test.cc | 15 ++-- utils/show.cc | 17 ++-- 55 files changed, 718 insertions(+), 601 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 3881457cd3..a2c6d4879d 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -73,7 +73,7 @@ jobs: cat "$GITHUB_OUTPUT" code-style: - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 needs: [ what-to-make ] if: ${{ needs.what-to-make.outputs.test-style == 'true' }} steps: @@ -90,8 +90,9 @@ jobs: run: | set -ex wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - - sudo add-apt-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main" - sudo apt-get install -y clang-format-17 + sudo add-apt-repository "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-20 main" + sudo apt update + sudo apt install -y clang-format-20 - name: Get NPM uses: actions/setup-node@v4 with: @@ -233,11 +234,13 @@ jobs: - name: Get Dependencies run: | set -ex - sudo apt-get update - sudo apt-get install -y --no-install-recommends \ + wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - + sudo add-apt-repository "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-20 main" + sudo apt update + sudo apt install -y --no-install-recommends \ ca-certificates \ clang \ - clang-tidy \ + clang-tidy-20 \ cmake \ gettext \ libcurl4-openssl-dev \ @@ -249,10 +252,6 @@ jobs: libpsl-dev \ libssl-dev \ ninja-build - - name: Get NPM - uses: actions/setup-node@v4 - with: - node-version: lts/* - name: Get Source uses: actions/checkout@v4 with: @@ -280,7 +279,7 @@ jobs: if grep 'warning:' makelog; then exit 1; fi clang-tidy-libtransmission-win32: - runs-on: windows-2022 + runs-on: windows-2025 needs: [ what-to-make ] if: ${{ needs.what-to-make.outputs.make-core == 'true' || needs.what-to-make.outputs.make-tests == 'true' }} steps: diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a4bf12363..9cfe297049 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -801,14 +801,14 @@ if(RUN_CLANG_TIDY) tr_get_required_flag(RUN_CLANG_TIDY CLANG_TIDY_IS_REQUIRED) message(STATUS "Looking for clang-tidy") - find_program(CLANG_TIDY clang-tidy) + find_program(CLANG_TIDY NAMES clang-tidy-20 clang-tidy) if(CLANG_TIDY STREQUAL "CLANG_TIDY-NOTFOUND") message(STATUS "Looking for clang-tidy - not found") if(CLANG_TIDY_IS_REQUIRED) message(FATAL_ERROR "clang-tidy is required but wasn't found") endif() else() - message(STATUS "Looking for clang-tidy - found") + message(STATUS "Looking for clang-tidy - found: ${CLANG_TIDY}") set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY}") endif() endif() diff --git a/code_style.sh b/code_style.sh index 01cd6733c8..2db5b1348b 100755 --- a/code_style.sh +++ b/code_style.sh @@ -40,10 +40,10 @@ find_cfiles() { ! \( $(get_find_path_args $(trim_comments .clang-format-ignore)) \) "$@" } -# We're targeting clang-format version 17 and other versions give slightly -# different results, so prefer `clang-format-17` if it's installed. +# We're targeting clang-format version 20 and other versions give slightly +# different results, so prefer `clang-format-20` if it's installed. clang_format_exe_names=( - 'clang-format-17' + 'clang-format-20' 'clang-format' ) for name in ${clang_format_exe_names[@]}; do diff --git a/daemon/daemon.cc b/daemon/daemon.cc index 70e31aef78..51254ca950 100644 --- a/daemon/daemon.cc +++ b/daemon/daemon.cc @@ -207,11 +207,12 @@ auto onFileAdded(tr_session* session, std::string_view dirname, std::string_view auto error = tr_error{}; if (!tr_file_read(filename, content, &error)) { - tr_logAddWarn(fmt::format( - fmt::runtime(_("Couldn't read '{path}': {error} ({error_code})")), - fmt::arg("path", basename), - fmt::arg("error", error.message()), - fmt::arg("error_code", error.code()))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("Couldn't read '{path}': {error} ({error_code})")), + fmt::arg("path", basename), + fmt::arg("error", error.message()), + fmt::arg("error_code", error.code()))); retry = true; } else @@ -246,11 +247,12 @@ auto onFileAdded(tr_session* session, std::string_view dirname, std::string_view if (auto error = tr_error{}; !tr_sys_path_remove(filename, &error)) { - tr_logAddError(fmt::format( - fmt::runtime(_("Couldn't remove '{path}': {error} ({error_code})")), - fmt::arg("path", basename), - fmt::arg("error", error.message()), - fmt::arg("error_code", error.code()))); + tr_logAddError( + fmt::format( + fmt::runtime(_("Couldn't remove '{path}': {error} ({error_code})")), + fmt::arg("path", basename), + fmt::arg("error", error.message()), + fmt::arg("error_code", error.code()))); } } else @@ -722,10 +724,11 @@ void tr_daemon::reconfigure() { auto error = tr_error{}; error.set_from_errno(errno); - tr_logAddError(fmt::format( - fmt::runtime(_("Failed to reload: Failed to get current monotonic time: {errmsg} ({errno})")), - fmt::arg("errmsg", error.message()), - fmt::arg("errno", error.code()))); + tr_logAddError( + fmt::format( + fmt::runtime(_("Failed to reload: Failed to get current monotonic time: {errmsg} ({errno})")), + fmt::arg("errmsg", error.message()), + fmt::arg("errno", error.code()))); return; } @@ -814,11 +817,12 @@ int tr_daemon::start([[maybe_unused]] bool foreground) } else { - tr_logAddError(fmt::format( - fmt::runtime(_("Couldn't save '{path}': {error} ({error_code})")), - fmt::arg("path", sz_pid_filename), - fmt::arg("error", error.message()), - fmt::arg("error_code", error.code()))); + tr_logAddError( + fmt::format( + fmt::runtime(_("Couldn't save '{path}': {error} ({error_code})")), + fmt::arg("path", sz_pid_filename), + fmt::arg("error", error.message()), + fmt::arg("error_code", error.code()))); } } @@ -887,20 +891,22 @@ int tr_daemon::start([[maybe_unused]] bool foreground) if (status_ev == nullptr) { auto const error_code = errno; - tr_logAddError(fmt::format( - fmt::runtime(_("Couldn't create event: {error} ({error_code})")), - fmt::arg("error", tr_strerror(error_code)), - fmt::arg("error_code", error_code))); + tr_logAddError( + fmt::format( + fmt::runtime(_("Couldn't create event: {error} ({error_code})")), + fmt::arg("error", tr_strerror(error_code)), + fmt::arg("error_code", error_code))); goto CLEANUP; } if (event_add(status_ev, &one_sec) == -1) { auto const error_code = errno; - tr_logAddError(fmt::format( - fmt::runtime(_("Couldn't add event: {error} ({error_code})")), - fmt::arg("error", tr_strerror(error_code)), - fmt::arg("error_code", error_code))); + tr_logAddError( + fmt::format( + fmt::runtime(_("Couldn't add event: {error} ({error_code})")), + fmt::arg("error", tr_strerror(error_code)), + fmt::arg("error_code", error_code))); goto CLEANUP; } } @@ -911,10 +917,11 @@ int tr_daemon::start([[maybe_unused]] bool foreground) if (event_base_dispatch(ev_base_) == -1) { auto const error_code = errno; - tr_logAddError(fmt::format( - fmt::runtime(_("Couldn't launch daemon event loop: {error} ({error_code})")), - fmt::arg("error", tr_strerror(error_code)), - fmt::arg("error_code", error_code))); + tr_logAddError( + fmt::format( + fmt::runtime(_("Couldn't launch daemon event loop: {error} ({error_code})")), + fmt::arg("error", tr_strerror(error_code)), + fmt::arg("error_code", error_code))); goto CLEANUP; } diff --git a/gtk/.clang-tidy b/gtk/.clang-tidy index 9f5bbaa512..12824215d2 100644 --- a/gtk/.clang-tidy +++ b/gtk/.clang-tidy @@ -6,6 +6,7 @@ Checks: > bugprone-*, -bugprone-narrowing-conversions, cert-*, + -cert-int09-c, cppcoreguidelines-*, -cppcoreguidelines-avoid-const-or-ref-data-members, -cppcoreguidelines-avoid-magic-numbers, @@ -18,6 +19,7 @@ Checks: > -modernize-use-trailing-return-type, performance-*, readability-*, + -readability-enum-initial-value, -readability-function-cognitive-complexity, -readability-identifier-length, -readability-magic-numbers, diff --git a/gtk/Actions.cc b/gtk/Actions.cc index 8b5e5c8ba3..9b6d68c7bd 100644 --- a/gtk/Actions.cc +++ b/gtk/Actions.cc @@ -239,9 +239,10 @@ Glib::RefPtr gtr_shortcuts_get_from_menu(Glib::RefPtrappend(Gtk::Shortcut::create( - Gtk::ShortcutTrigger::parse_string(action_accel), - Gtk::NamedAction::create(action_name))); + result->append( + Gtk::Shortcut::create( + Gtk::ShortcutTrigger::parse_string(action_accel), + Gtk::NamedAction::create(action_name))); } for (auto it = link->iterate_item_links(i); it->next();) diff --git a/gtk/Application.cc b/gtk/Application.cc index 3d4101c048..87ab9633cc 100644 --- a/gtk/Application.cc +++ b/gtk/Application.cc @@ -396,11 +396,12 @@ void register_magnet_link_handler() } catch (Gio::Error const& e) { - gtr_warning(fmt::format( - fmt::runtime(_("Couldn't register Transmission as a {content_type} handler: {error} ({error_code})")), - fmt::arg("content_type", content_type), - fmt::arg("error", e.what()), - fmt::arg("error_code", static_cast(e.code())))); + gtr_warning( + fmt::format( + fmt::runtime(_("Couldn't register Transmission as a {content_type} handler: {error} ({error_code})")), + fmt::arg("content_type", content_type), + fmt::arg("error", e.what()), + fmt::arg("error_code", static_cast(e.code())))); } } diff --git a/gtk/DetailsDialog.cc b/gtk/DetailsDialog.cc index 80bdb27607..4b207c3dca 100644 --- a/gtk/DetailsDialog.cc +++ b/gtk/DetailsDialog.cc @@ -977,11 +977,12 @@ void DetailsDialog::Impl::refreshInfo(std::vector const& torrents) } else { - auto const downloaded_str = tr_strlsize(std::accumulate( - std::begin(stats), - std::end(stats), - uint64_t{ 0 }, - [](auto sum, auto const* st) { return sum + st->downloadedEver; })); + auto const downloaded_str = tr_strlsize( + std::accumulate( + std::begin(stats), + std::end(stats), + uint64_t{ 0 }, + [](auto sum, auto const* st) { return sum + st->downloadedEver; })); auto const failed = std::accumulate( std::begin(stats), diff --git a/gtk/FileList.cc b/gtk/FileList.cc index d0d89674ba..fd8b07b6fd 100644 --- a/gtk/FileList.cc +++ b/gtk/FileList.cc @@ -821,13 +821,14 @@ struct rename_data void FileList::Impl::on_rename_done(Glib::ustring const& path_string, Glib::ustring const& newname, int error) { - rename_done_tags_.push(Glib::signal_idle().connect( - [this, path_string, newname, error]() - { - rename_done_tags_.pop(); - on_rename_done_idle(path_string, newname, error); - return false; - })); + rename_done_tags_.push( + Glib::signal_idle().connect( + [this, path_string, newname, error]() + { + rename_done_tags_.pop(); + on_rename_done_idle(path_string, newname, error); + return false; + })); } void FileList::Impl::on_rename_done_idle(Glib::ustring const& path_string, Glib::ustring const& newname, int error) diff --git a/gtk/MainWindow.cc b/gtk/MainWindow.cc index b7e9745411..e5cddfc186 100644 --- a/gtk/MainWindow.cc +++ b/gtk/MainWindow.cc @@ -379,12 +379,13 @@ void MainWindow::Impl::syncAltSpeedButton() { bool const b = gtr_pref_flag_get(TR_KEY_alt_speed_enabled); alt_speed_button_->set_active(b); - alt_speed_button_->set_tooltip_text(fmt::format( - fmt::runtime( - b ? _("Click to disable Alternative Speed Limits\n ({download_speed} down, {upload_speed} up)") : - _("Click to enable Alternative Speed Limits\n ({download_speed} down, {upload_speed} up)")), - fmt::arg("download_speed", Speed{ gtr_pref_int_get(TR_KEY_alt_speed_down), Speed::Units::KByps }.to_string()), - fmt::arg("upload_speed", Speed{ gtr_pref_int_get(TR_KEY_alt_speed_up), Speed::Units::KByps }.to_string()))); + alt_speed_button_->set_tooltip_text( + fmt::format( + fmt::runtime( + b ? _("Click to disable Alternative Speed Limits\n ({download_speed} down, {upload_speed} up)") : + _("Click to enable Alternative Speed Limits\n ({download_speed} down, {upload_speed} up)")), + fmt::arg("download_speed", Speed{ gtr_pref_int_get(TR_KEY_alt_speed_down), Speed::Units::KByps }.to_string()), + fmt::arg("upload_speed", Speed{ gtr_pref_int_get(TR_KEY_alt_speed_up), Speed::Units::KByps }.to_string()))); } void MainWindow::Impl::alt_speed_toggled_cb() diff --git a/gtk/MessageLogWindow.cc b/gtk/MessageLogWindow.cc index 0f3345a145..f749b05125 100644 --- a/gtk/MessageLogWindow.cc +++ b/gtk/MessageLogWindow.cc @@ -491,9 +491,10 @@ MessageLogWindow::Impl::Impl( , filter_(Gtk::TreeModelFilter::create(store_)) , sort_(Gtk::TreeModelSort::create(filter_)) , maxLevel_(static_cast(gtr_pref_int_get(TR_KEY_message_level))) - , refresh_tag_(Glib::signal_timeout().connect_seconds( - sigc::mem_fun(*this, &Impl::onRefresh), - SECONDARY_WINDOW_REFRESH_INTERVAL_SECONDS)) + , refresh_tag_( + Glib::signal_timeout().connect_seconds( + sigc::mem_fun(*this, &Impl::onRefresh), + SECONDARY_WINDOW_REFRESH_INTERVAL_SECONDS)) { /** *** toolbar diff --git a/gtk/Notify.cc b/gtk/Notify.cc index 4d5817a916..a05476c96b 100644 --- a/gtk/Notify.cc +++ b/gtk/Notify.cc @@ -144,11 +144,12 @@ void dbus_proxy_ready_callback(Glib::RefPtr& res) } catch (Glib::Error const& e) { - gtr_warning(fmt::format( - fmt::runtime(_("Couldn't create proxy for '{bus}': {error} ({error_code})")), - fmt::arg("bus", NotificationsDbusName), - fmt::arg("error", TR_GLIB_EXCEPTION_WHAT(e)), - fmt::arg("error_code", e.code()))); + gtr_warning( + fmt::format( + fmt::runtime(_("Couldn't create proxy for '{bus}': {error} ({error_code})")), + fmt::arg("bus", NotificationsDbusName), + fmt::arg("error", TR_GLIB_EXCEPTION_WHAT(e)), + fmt::arg("error_code", e.code()))); return; } diff --git a/gtk/Session.cc b/gtk/Session.cc index eb6b069c45..93a07df473 100644 --- a/gtk/Session.cc +++ b/gtk/Session.cc @@ -318,12 +318,13 @@ void rename_torrent(Glib::RefPtr const& file) } catch (Glib::Error const& e) { - gtr_message(fmt::format( - fmt::runtime(_("Couldn't rename '{old_path}' as '{path}': {error} ({error_code})")), - fmt::arg("old_path", old_name), - fmt::arg("path", new_name), - fmt::arg("error", e.what()), - fmt::arg("error_code", e.code()))); + gtr_message( + fmt::format( + fmt::runtime(_("Couldn't rename '{old_path}' as '{path}': {error} ({error_code})")), + fmt::arg("old_path", old_name), + fmt::arg("path", new_name), + fmt::arg("error", e.what()), + fmt::arg("error_code", e.code()))); } } @@ -807,11 +808,12 @@ void Session::Impl::add_file_async_callback( } catch (Glib::Error const& e) { - gtr_message(fmt::format( - fmt::runtime(_("Couldn't read '{path}': {error} ({error_code})")), - fmt::arg("path", file->get_parse_name()), - fmt::arg("error", e.what()), - fmt::arg("error_code", e.code()))); + gtr_message( + fmt::format( + fmt::runtime(_("Couldn't read '{path}': {error} ({error_code})")), + fmt::arg("path", file->get_parse_name()), + fmt::arg("error", e.what()), + fmt::arg("error_code", e.code()))); } dec_busy(); @@ -1070,12 +1072,13 @@ bool gtr_inhibit_hibernation(guint32& cookie) std::string(SessionManagerObjectPath), std::string(SessionManagerInterface), "Inhibit", - Glib::VariantContainerBase::create_tuple({ - Glib::Variant::create(application), - Glib::Variant::create(toplevel_xid), - Glib::Variant::create(reason), - Glib::Variant::create(flags), - }), + Glib::VariantContainerBase::create_tuple( + { + Glib::Variant::create(application), + Glib::Variant::create(toplevel_xid), + Glib::Variant::create(reason), + Glib::Variant::create(flags), + }), std::string(SessionManagerServiceName), 1000); diff --git a/gtk/Torrent.cc b/gtk/Torrent.cc index 421c05d8bb..170e2ed0e6 100644 --- a/gtk/Torrent.cc +++ b/gtk/Torrent.cc @@ -274,10 +274,11 @@ Torrent::ChangeFlags Torrent::Impl::update_cache() update_cache_value(cache_.activity, stats->activity, result, ChangeFlag::ACTIVITY); update_cache_value( cache_.activity_percent_done, - Percents(std::clamp( - stats->activity == TR_STATUS_SEED && has_seed_ratio ? stats->seedRatioPercentDone : stats->percentDone, - 0.0F, - 1.0F)), + Percents( + std::clamp( + stats->activity == TR_STATUS_SEED && has_seed_ratio ? stats->seedRatioPercentDone : stats->percentDone, + 0.0F, + 1.0F)), result, ChangeFlag::PERCENT_DONE); update_cache_value(cache_.finished, stats->finished, result, ChangeFlag::FINISHED); diff --git a/gtk/Utils.cc b/gtk/Utils.cc index 5f6ed0e0e0..75c75af459 100644 --- a/gtk/Utils.cc +++ b/gtk/Utils.cc @@ -541,11 +541,12 @@ bool gtr_file_trash_or_remove(std::string const& filename, tr_error* error) catch (Glib::Error const& e) { error->set(e.code(), TR_GLIB_EXCEPTION_WHAT(e)); - gtr_message(fmt::format( - fmt::runtime(_("Couldn't move '{path}' to trash: {error} ({error_code})")), - fmt::arg("path", filename), - fmt::arg("error", error->message()), - fmt::arg("error_code", error->code()))); + gtr_message( + fmt::format( + fmt::runtime(_("Couldn't move '{path}' to trash: {error} ({error_code})")), + fmt::arg("path", filename), + fmt::arg("error", error->message()), + fmt::arg("error_code", error->code()))); } } @@ -559,11 +560,12 @@ bool gtr_file_trash_or_remove(std::string const& filename, tr_error* error) catch (Glib::Error const& e) { error->set(e.code(), TR_GLIB_EXCEPTION_WHAT(e)); - gtr_message(fmt::format( - fmt::runtime(_("Couldn't remove '{path}': {error} ({error_code})")), - fmt::arg("path", filename), - fmt::arg("error", error->message()), - fmt::arg("error_code", error->code()))); + gtr_message( + fmt::format( + fmt::runtime(_("Couldn't remove '{path}': {error} ({error_code})")), + fmt::arg("path", filename), + fmt::arg("error", error->message()), + fmt::arg("error_code", error->code()))); result = false; } } diff --git a/libtransmission/.clang-tidy b/libtransmission/.clang-tidy index 37b9aeae28..e36096bce8 100644 --- a/libtransmission/.clang-tidy +++ b/libtransmission/.clang-tidy @@ -1,6 +1,7 @@ --- HeaderFilterRegex: .*/libtransmission/.* +# TODO: Enable `portability-template-virtual-member-function` after https://github.com/llvm/llvm-project/issues/139031 is fixed # PRs welcome to fix & re-enable any of these explicitly-disabled checks Checks: > bugprone-*, @@ -10,6 +11,7 @@ Checks: > -bugprone-narrowing-conversions, cert-*, -cert-err58-cpp, + -cert-int09-c, clang-analyzer-*, -clang-analyzer-optin.core.EnumCastOutOfRange, cppcoreguidelines-avoid-do-while, @@ -34,7 +36,9 @@ Checks: > performance-*, -performance-move-const-arg, portability-*, + -portability-template-virtual-member-function, readability-*, + -readability-enum-initial-value, -readability-function-cognitive-complexity, -readability-identifier-length, -readability-magic-numbers, diff --git a/libtransmission/block-info.h b/libtransmission/block-info.h index 7223a8d189..02696b8957 100644 --- a/libtransmission/block-info.h +++ b/libtransmission/block-info.h @@ -100,7 +100,7 @@ public: // Location of the first byte (+ optional offset and length) in `piece` [[nodiscard]] constexpr auto piece_loc(tr_piece_index_t piece, uint32_t offset = {}, uint32_t length = {}) const noexcept { - return byte_loc(uint64_t{ piece } * piece_size() + offset + length); + return byte_loc((uint64_t{ piece } * piece_size()) + offset + length); } [[nodiscard]] constexpr tr_block_span_t block_span_for_piece(tr_piece_index_t const piece) const noexcept @@ -130,7 +130,7 @@ private: // Location of the last byte in `piece`. [[nodiscard]] constexpr Location piece_last_loc(tr_piece_index_t const piece) const noexcept { - return byte_loc(static_cast(piece) * piece_size() + piece_size(piece) - 1); + return byte_loc((static_cast(piece) * piece_size()) + piece_size(piece) - 1); } [[nodiscard]] constexpr bool is_initialized() const noexcept diff --git a/libtransmission/blocklist.cc b/libtransmission/blocklist.cc index f3d514e060..41f94b01fa 100644 --- a/libtransmission/blocklist.cc +++ b/libtransmission/blocklist.cc @@ -58,30 +58,33 @@ void save(std::string_view filename, address_range_t const* ranges, size_t n_ran auto out = std::ofstream{ tr_pathbuf{ filename }, std::ios_base::out | std::ios_base::trunc | std::ios_base::binary }; if (!out.is_open()) { - tr_logAddWarn(fmt::format( - fmt::runtime(_("Couldn't read '{path}': {error} ({error_code})")), - fmt::arg("path", filename), - fmt::arg("error", tr_strerror(errno)), - fmt::arg("error_code", errno))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("Couldn't read '{path}': {error} ({error_code})")), + fmt::arg("path", filename), + fmt::arg("error", tr_strerror(errno)), + fmt::arg("error_code", errno))); return; } if (!out.write(std::data(BinContentsPrefix), std::size(BinContentsPrefix)) || !out.write(reinterpret_cast(ranges), n_ranges * sizeof(*ranges))) { - tr_logAddWarn(fmt::format( - fmt::runtime(_("Couldn't save '{path}': {error} ({error_code})")), - fmt::arg("path", filename), - fmt::arg("error", tr_strerror(errno)), - fmt::arg("error_code", errno))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("Couldn't save '{path}': {error} ({error_code})")), + fmt::arg("path", filename), + fmt::arg("error", tr_strerror(errno)), + fmt::arg("error_code", errno))); } else { - tr_logAddInfo(fmt::format( - fmt::runtime( - tr_ngettext("Blocklist '{path}' has {count} entry", "Blocklist '{path}' has {count} entries", n_ranges)), - fmt::arg("path", tr_sys_path_basename(filename)), - fmt::arg("count", n_ranges))); + tr_logAddInfo( + fmt::format( + fmt::runtime( + tr_ngettext("Blocklist '{path}' has {count} entry", "Blocklist '{path}' has {count} entries", n_ranges)), + fmt::arg("path", tr_sys_path_basename(filename)), + fmt::arg("count", n_ranges))); } out.close(); @@ -237,11 +240,12 @@ auto parseFile(std::string_view filename) auto in = std::ifstream{ tr_pathbuf{ filename } }; if (!in.is_open()) { - tr_logAddWarn(fmt::format( - fmt::runtime(_("Couldn't read '{path}': {error} ({error_code})")), - fmt::arg("path", filename), - fmt::arg("error", tr_strerror(errno)), - fmt::arg("error_code", errno))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("Couldn't read '{path}': {error} ({error_code})")), + fmt::arg("path", filename), + fmt::arg("error", tr_strerror(errno)), + fmt::arg("error_code", errno))); return ranges; } @@ -335,11 +339,12 @@ void Blocklists::Blocklist::ensureLoaded() const auto const file_info = tr_sys_path_get_info(bin_file_, 0, &error); if (error) { - tr_logAddWarn(fmt::format( - fmt::runtime(_("Couldn't read '{path}': {error} ({error_code})")), - fmt::arg("path", bin_file_), - fmt::arg("error", error.message()), - fmt::arg("error_code", error.code()))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("Couldn't read '{path}': {error} ({error_code})")), + fmt::arg("path", bin_file_), + fmt::arg("error", error.message()), + fmt::arg("error_code", error.code()))); } if (!file_info) { @@ -350,11 +355,12 @@ void Blocklists::Blocklist::ensureLoaded() const auto in = std::ifstream{ bin_file_, std::ios_base::in | std::ios_base::binary }; if (!in) { - tr_logAddWarn(fmt::format( - fmt::runtime(_("Couldn't read '{path}': {error} ({error_code})")), - fmt::arg("path", bin_file_), - fmt::arg("error", tr_strerror(errno)), - fmt::arg("error_code", errno))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("Couldn't read '{path}': {error} ({error_code})")), + fmt::arg("path", bin_file_), + fmt::arg("error", tr_strerror(errno)), + fmt::arg("error_code", errno))); return; } @@ -400,11 +406,14 @@ void Blocklists::Blocklist::ensureLoaded() const rules_.emplace_back(range); } - tr_logAddInfo(fmt::format( - fmt::runtime( - tr_ngettext("Blocklist '{path}' has {count} entry", "Blocklist '{path}' has {count} entries", std::size(rules_))), - fmt::arg("path", tr_sys_path_basename(bin_file_)), - fmt::arg("count", std::size(rules_)))); + tr_logAddInfo( + fmt::format( + fmt::runtime(tr_ngettext( + "Blocklist '{path}' has {count} entry", + "Blocklist '{path}' has {count} entries", + std::size(rules_))), + fmt::arg("path", tr_sys_path_basename(bin_file_)), + fmt::arg("count", std::size(rules_)))); } bool Blocklists::Blocklist::contains(tr_address const& addr) const @@ -471,11 +480,12 @@ std::optional Blocklists::Blocklist::saveNew( auto const copied = tr_sys_path_copy(tr_pathbuf{ external_file }, src_file.c_str(), &error); if (error) { - tr_logAddWarn(fmt::format( - fmt::runtime(_("Couldn't save '{path}': {error} ({error_code})")), - fmt::arg("path", src_file), - fmt::arg("error", error.message()), - fmt::arg("error_code", error.code()))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("Couldn't save '{path}': {error} ({error_code})")), + fmt::arg("path", src_file), + fmt::arg("error", error.message()), + fmt::arg("error_code", error.code()))); } if (!copied) { diff --git a/libtransmission/crypto-utils.h b/libtransmission/crypto-utils.h index 10a7efb980..67c8891fbe 100644 --- a/libtransmission/crypto-utils.h +++ b/libtransmission/crypto-utils.h @@ -170,7 +170,7 @@ T tr_rand_obj() */ [[nodiscard]] std::string tr_base64_decode(std::string_view input); -using tr_sha1_string = tr_strbuf; +using tr_sha1_string = tr_strbuf; /** * @brief Generate an ascii hex string for a sha1 digest. @@ -182,7 +182,7 @@ using tr_sha1_string = tr_strbuf; */ [[nodiscard]] std::optional tr_sha1_from_string(std::string_view hex); -using tr_sha256_string = tr_strbuf; +using tr_sha256_string = tr_strbuf; /** * @brief Generate an ascii hex string for a sha256 digest. diff --git a/libtransmission/favicon-cache.h b/libtransmission/favicon-cache.h index a239fa9f46..92745c618a 100644 --- a/libtransmission/favicon-cache.h +++ b/libtransmission/favicon-cache.h @@ -44,9 +44,7 @@ public: return iter != std::end(icons_) ? &iter->second : nullptr; } - void load( // - std::string_view url_in, - IconFunc callback = [](Icon const&) { /*default callback is a no-op */ }) + void load(std::string_view url_in, IconFunc callback = [](Icon const&) { /*default callback is a no-op */ }) { std::call_once(scan_once_flag_, &FaviconCache::scan_file_cache, this); diff --git a/libtransmission/ip-cache.cc b/libtransmission/ip-cache.cc index 9ca9176ee5..fa5e0abf92 100644 --- a/libtransmission/ip-cache.cc +++ b/libtransmission/ip-cache.cc @@ -286,10 +286,11 @@ void tr_ip_cache::update_source_addr(tr_address_type type) noexcept if (auto const& source_addr = get_global_source_address(bind_addr(type), err); source_addr) { set_source_addr(*source_addr); - tr_logAddDebug(fmt::format( - fmt::runtime(_("Successfully updated source {protocol} address to {ip}")), - fmt::arg("protocol", protocol), - fmt::arg("ip", source_addr->display_name()))); + tr_logAddDebug( + fmt::format( + fmt::runtime(_("Successfully updated source {protocol} address to {ip}")), + fmt::arg("protocol", protocol), + fmt::arg("ip", source_addr->display_name()))); } else { @@ -334,11 +335,12 @@ void tr_ip_cache::on_response_ip_query(tr_address_type type, tr_web::FetchRespon success = true; upkeep_timers_[type]->set_interval(UpkeepInterval); - tr_logAddDebug(fmt::format( - fmt::runtime(_("Successfully updated global {type} address to {ip} using {url}")), - fmt::arg("type", protocol), - fmt::arg("ip", addr->display_name()), - fmt::arg("url", IPQueryServices[type][ix_service]))); + tr_logAddDebug( + fmt::format( + fmt::runtime(_("Successfully updated global {type} address to {ip} using {url}")), + fmt::arg("type", protocol), + fmt::arg("ip", addr->display_name()), + fmt::arg("url", IPQueryServices[type][ix_service]))); } } @@ -351,12 +353,13 @@ void tr_ip_cache::on_response_ip_query(tr_address_type type, tr_web::FetchRespon return; } - tr_logAddDebug(fmt::format( - "Couldn't obtain global {} address, HTTP status = {}, did_connect = {}, did_timeout = {}", - protocol, - response.status, - response.did_connect, - response.did_timeout)); + tr_logAddDebug( + fmt::format( + "Couldn't obtain global {} address, HTTP status = {}, did_connect = {}, did_timeout = {}", + protocol, + response.status, + response.did_connect, + response.did_timeout)); unset_global_addr(type); upkeep_timers_[type]->set_interval(RetryUpkeepInterval); } diff --git a/libtransmission/lru-cache.h b/libtransmission/lru-cache.h index 124e272802..3d87a263ec 100644 --- a/libtransmission/lru-cache.h +++ b/libtransmission/lru-cache.h @@ -50,7 +50,7 @@ public: } } - void erase_if(std::function test) + void erase_if(std::function const& test) { for (auto& entry : entries_) { diff --git a/libtransmission/makemeta.cc b/libtransmission/makemeta.cc index a44b16a626..5ae9cd3bb1 100644 --- a/libtransmission/makemeta.cc +++ b/libtransmission/makemeta.cc @@ -76,11 +76,12 @@ void walkTree(std::string_view const top, std::string_view const subpath, std::s auto const info = tr_sys_path_get_info(path, 0, &error); if (error) { - tr_logAddWarn(fmt::format( - fmt::runtime(_("Skipping '{path}': {error} ({error_code})")), - fmt::arg("path", path), - fmt::arg("error", error.message()), - fmt::arg("error_code", error.code()))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("Skipping '{path}': {error} ({error_code})")), + fmt::arg("path", path), + fmt::arg("error", error.message()), + fmt::arg("error_code", error.code()))); } if (!info) { diff --git a/libtransmission/net.cc b/libtransmission/net.cc index 00f70f9a74..4017fc29fb 100644 --- a/libtransmission/net.cc +++ b/libtransmission/net.cc @@ -198,10 +198,11 @@ tr_socket_t createSocket(int domain, int type) { if (sockerrno != EAFNOSUPPORT) { - tr_logAddWarn(fmt::format( - fmt::runtime(_("Couldn't create socket: {error} ({error_code})")), - fmt::arg("error", tr_net_strerror(sockerrno)), - fmt::arg("error_code", sockerrno))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("Couldn't create socket: {error} ({error_code})")), + fmt::arg("error", tr_net_strerror(sockerrno)), + fmt::arg("error_code", sockerrno))); } return TR_BAD_SOCKET; @@ -274,12 +275,13 @@ tr_socket_t tr_net_open_peer_socket(tr_session* session, tr_socket_address const if (bind(s, reinterpret_cast(&source_sock), sourcelen) == -1) { - tr_logAddWarn(fmt::format( - fmt::runtime(_("Couldn't set source address {address} on {socket}: {error} ({error_code})")), - fmt::arg("address", source_addr.display_name()), - fmt::arg("socket", s), - fmt::arg("error", tr_net_strerror(sockerrno)), - fmt::arg("error_code", sockerrno))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("Couldn't set source address {address} on {socket}: {error} ({error_code})")), + fmt::arg("address", source_addr.display_name()), + fmt::arg("socket", s), + fmt::arg("error", tr_net_strerror(sockerrno)), + fmt::arg("error_code", sockerrno))); tr_net_close_socket(s); return TR_BAD_SOCKET; } @@ -293,13 +295,14 @@ tr_socket_t tr_net_open_peer_socket(tr_session* session, tr_socket_address const if (auto const tmperrno = sockerrno; (tmperrno != ECONNREFUSED && tmperrno != ENETUNREACH && tmperrno != EHOSTUNREACH) || addr.is_ipv4()) { - tr_logAddWarn(fmt::format( - fmt::runtime(_("Couldn't connect socket {socket} to {address}:{port}: {error} ({error_code})")), - fmt::arg("socket", s), - fmt::arg("address", addr.display_name()), - fmt::arg("port", port.host()), - fmt::arg("error", tr_net_strerror(tmperrno)), - fmt::arg("error_code", tmperrno))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("Couldn't connect socket {socket} to {address}:{port}: {error} ({error_code})")), + fmt::arg("socket", s), + fmt::arg("address", addr.display_name()), + fmt::arg("port", port.host()), + fmt::arg("error", tr_net_strerror(tmperrno)), + fmt::arg("error_code", tmperrno))); } tr_net_close_socket(s); @@ -351,15 +354,16 @@ tr_socket_t tr_netBindTCPImpl(tr_address const& addr, tr_port port, bool suppres if (!suppress_msgs) { - tr_logAddError(fmt::format( - fmt::runtime( - err == EADDRINUSE ? - _("Couldn't bind port {port} on {address}: {error} ({error_code}) -- Is another copy of Transmission already running?") : - _("Couldn't bind port {port} on {address}: {error} ({error_code})")), - fmt::arg("address", addr.display_name()), - fmt::arg("port", port.host()), - fmt::arg("error", tr_net_strerror(err)), - fmt::arg("error_code", err))); + tr_logAddError( + fmt::format( + fmt::runtime( + err == EADDRINUSE ? + _("Couldn't bind port {port} on {address}: {error} ({error_code}) -- Is another copy of Transmission already running?") : + _("Couldn't bind port {port} on {address}: {error} ({error_code})")), + fmt::arg("address", addr.display_name()), + fmt::arg("port", port.host()), + fmt::arg("error", tr_net_strerror(err)), + fmt::arg("error_code", err))); } tr_net_close_socket(fd); diff --git a/libtransmission/open-files.cc b/libtransmission/open-files.cc index b7b5af28cf..163a167fbb 100644 --- a/libtransmission/open-files.cc +++ b/libtransmission/open-files.cc @@ -166,11 +166,12 @@ std::optional tr_open_files::get( dir.popdir(); if (!tr_sys_dir_create(dir, TR_SYS_DIR_CREATE_PARENTS, 0777, &error)) { - tr_logAddError(fmt::format( - fmt::runtime(_("Couldn't create '{path}': {error} ({error_code})")), - fmt::arg("path", dir), - fmt::arg("error", error.message()), - fmt::arg("error_code", error.code()))); + tr_logAddError( + fmt::format( + fmt::runtime(_("Couldn't create '{path}': {error} ({error_code})")), + fmt::arg("path", dir), + fmt::arg("error", error.message()), + fmt::arg("error_code", error.code()))); return {}; } } @@ -188,11 +189,12 @@ std::optional tr_open_files::get( auto const fd = tr_sys_file_open(filename, flags, 0666, &error); if (!is_open(fd)) { - tr_logAddError(fmt::format( - fmt::runtime(_("Couldn't open '{path}': {error} ({error_code})")), - fmt::arg("path", filename), - fmt::arg("error", error.message()), - fmt::arg("error_code", error.code()))); + tr_logAddError( + fmt::format( + fmt::runtime(_("Couldn't open '{path}': {error} ({error_code})")), + fmt::arg("path", filename), + fmt::arg("error", error.message()), + fmt::arg("error_code", error.code()))); return {}; } @@ -216,11 +218,12 @@ std::optional tr_open_files::get( if (!success) { - tr_logAddError(fmt::format( - fmt::runtime(_("Couldn't preallocate '{path}': {error} ({error_code})")), - fmt::arg("path", filename), - fmt::arg("error", error.message()), - fmt::arg("error_code", error.code()))); + tr_logAddError( + fmt::format( + fmt::runtime(_("Couldn't preallocate '{path}': {error} ({error_code})")), + fmt::arg("path", filename), + fmt::arg("error", error.message()), + fmt::arg("error_code", error.code()))); tr_sys_file_close(fd); return {}; } @@ -235,11 +238,12 @@ std::optional tr_open_files::get( // https://bugs.launchpad.net/ubuntu/+source/transmission/+bug/318249 if (resize_needed && !tr_sys_file_truncate(fd, file_size, &error)) { - tr_logAddWarn(fmt::format( - fmt::runtime(_("Couldn't truncate '{path}': {error} ({error_code})")), - fmt::arg("path", filename), - fmt::arg("error", error.message()), - fmt::arg("error_code", error.code()))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("Couldn't truncate '{path}': {error} ({error_code})")), + fmt::arg("path", filename), + fmt::arg("error", error.message()), + fmt::arg("error_code", error.code()))); tr_sys_file_close(fd); return {}; } diff --git a/libtransmission/port-forwarding-natpmp.cc b/libtransmission/port-forwarding-natpmp.cc index e24d1017aa..6c8e0ea8b5 100644 --- a/libtransmission/port-forwarding-natpmp.cc +++ b/libtransmission/port-forwarding-natpmp.cc @@ -43,13 +43,14 @@ void log_val(char const* func, int ret) } else { - tr_logAddDebug(fmt::format( - "{} failed. Natpmp returned {} ({}); errno is {} ({})", - func, - ret, - strnatpmperr(ret), - errno, - tr_strerror(errno))); + tr_logAddDebug( + fmt::format( + "{} failed. Natpmp returned {} ({}); errno is {} ({})", + func, + ret, + strnatpmperr(ret), + errno, + tr_strerror(errno))); } } } // namespace diff --git a/libtransmission/port-forwarding-upnp.cc b/libtransmission/port-forwarding-upnp.cc index 7863df980a..3151ee4414 100644 --- a/libtransmission/port-forwarding-upnp.cc +++ b/libtransmission/port-forwarding-upnp.cc @@ -269,9 +269,10 @@ tr_port_forwarding_state tr_upnpPulse( #endif == UPNP_IGD_VALID_CONNECTED) { - tr_logAddInfo(fmt::format( - fmt::runtime(_("Found Internet Gateway Device '{url}'")), - fmt::arg("url", handle->urls.controlURL))); + tr_logAddInfo( + fmt::format( + fmt::runtime(_("Found Internet Gateway Device '{url}'")), + fmt::arg("url", handle->urls.controlURL))); tr_logAddInfo(fmt::format(fmt::runtime(_("Local Address is '{address}'")), fmt::arg("address", lanaddr.data()))); handle->state = UpnpState::Idle; handle->lanaddr = std::data(lanaddr); @@ -296,10 +297,11 @@ tr_port_forwarding_state tr_upnpPulse( (get_specific_port_mapping_entry(handle, "TCP") != UPNPCOMMAND_SUCCESS || get_specific_port_mapping_entry(handle, "UDP") != UPNPCOMMAND_SUCCESS)) { - tr_logAddInfo(fmt::format( - fmt::runtime(_("Local port {local_port} is not forwarded to {advertised_port}")), - fmt::arg("local_port", handle->local_port.host()), - fmt::arg("advertised_port", handle->advertised_port.host()))); + tr_logAddInfo( + fmt::format( + fmt::runtime(_("Local port {local_port} is not forwarded to {advertised_port}")), + fmt::arg("local_port", handle->local_port.host()), + fmt::arg("advertised_port", handle->advertised_port.host()))); handle->isMapped = false; } @@ -308,10 +310,11 @@ tr_port_forwarding_state tr_upnpPulse( tr_upnpDeletePortMapping(handle, "TCP", handle->advertised_port); tr_upnpDeletePortMapping(handle, "UDP", handle->advertised_port); - tr_logAddInfo(fmt::format( - fmt::runtime(_("Stopping port forwarding through '{url}', service '{type}'")), - fmt::arg("url", handle->urls.controlURL), - fmt::arg("type", handle->data.first.servicetype))); + tr_logAddInfo( + fmt::format( + fmt::runtime(_("Stopping port forwarding through '{url}', service '{type}'")), + fmt::arg("url", handle->urls.controlURL), + fmt::arg("type", handle->data.first.servicetype))); handle->isMapped = false; handle->state = UpnpState::Idle; @@ -341,19 +344,21 @@ tr_port_forwarding_state tr_upnpPulse( handle->isMapped = err_tcp == 0 || err_udp == 0; } - tr_logAddDebug(fmt::format( - fmt::runtime(_("Port forwarding through '{url}', service '{type}'. (local address: {address}:{port})")), - fmt::arg("url", handle->urls.controlURL), - fmt::arg("type", handle->data.first.servicetype), - fmt::arg("address", handle->lanaddr), - fmt::arg("port", local_port.host()))); + tr_logAddDebug( + fmt::format( + fmt::runtime(_("Port forwarding through '{url}', service '{type}'. (local address: {address}:{port})")), + fmt::arg("url", handle->urls.controlURL), + fmt::arg("type", handle->data.first.servicetype), + fmt::arg("address", handle->lanaddr), + fmt::arg("port", local_port.host()))); if (handle->isMapped) { - tr_logAddInfo(fmt::format( - fmt::runtime(_("Forwarded local port {local_port} to {advertised_port}")), - fmt::arg("local_port", local_port.host()), - fmt::arg("advertised_port", advertised_port.host()))); + tr_logAddInfo( + fmt::format( + fmt::runtime(_("Forwarded local port {local_port} to {advertised_port}")), + fmt::arg("local_port", local_port.host()), + fmt::arg("advertised_port", advertised_port.host()))); handle->advertised_port = advertised_port; handle->local_port = local_port; } diff --git a/libtransmission/port-forwarding.cc b/libtransmission/port-forwarding.cc index 064a6cc150..74fca47682 100644 --- a/libtransmission/port-forwarding.cc +++ b/libtransmission/port-forwarding.cc @@ -197,10 +197,11 @@ private: if (!std::empty(result.local_port) && !std::empty(result.advertised_port)) { mediator_.on_port_forwarded(result.advertised_port); - tr_logAddInfo(fmt::format( - fmt::runtime(_("Mapped private port {private_port} to public port {public_port}")), - fmt::arg("private_port", result.local_port.host()), - fmt::arg("public_port", result.advertised_port.host()))); + tr_logAddInfo( + fmt::format( + fmt::runtime(_("Mapped private port {private_port} to public port {public_port}")), + fmt::arg("private_port", result.local_port.host()), + fmt::arg("public_port", result.advertised_port.host()))); } upnp_state_ = tr_upnpPulse( @@ -213,10 +214,11 @@ private: if (auto const new_state = state(); new_state != old_state) { - tr_logAddInfo(fmt::format( - fmt::runtime(_("State changed from '{old_state}' to '{state}'")), - fmt::arg("old_state", getNatStateStr(old_state)), - fmt::arg("state", getNatStateStr(new_state)))); + tr_logAddInfo( + fmt::format( + fmt::runtime(_("State changed from '{old_state}' to '{state}'")), + fmt::arg("old_state", getNatStateStr(old_state)), + fmt::arg("state", getNatStateStr(new_state)))); } } diff --git a/libtransmission/rpc-server.cc b/libtransmission/rpc-server.cc index b70f57e6df..5b6ef56aa7 100644 --- a/libtransmission/rpc-server.cc +++ b/libtransmission/rpc-server.cc @@ -100,10 +100,11 @@ public: if (std::size(src) >= TrUnixAddrStrLen) { - tr_logAddError(fmt::format( - fmt::runtime(_("Unix socket path must be fewer than {count} characters (including '{prefix}' prefix)")), - fmt::arg("count", TrUnixAddrStrLen - 1), - fmt::arg("prefix", TrUnixSocketPrefix))); + tr_logAddError( + fmt::format( + fmt::runtime(_("Unix socket path must be fewer than {count} characters (including '{prefix}' prefix)")), + fmt::arg("count", TrUnixAddrStrLen - 1), + fmt::arg("prefix", TrUnixSocketPrefix))); return false; } unix_socket_path_ = src; @@ -342,9 +343,10 @@ void handle_web_client(struct evhttp_request* req, tr_rpc_server const* server) #endif auto remote_port = ev_uint16_t{}; evhttp_connection_get_peer(con, &remote_host, &remote_port); - tr_logAddWarn(fmt::format( - fmt::runtime(_("Rejected request from {host} (possible directory traversal attack)")), - fmt::arg("host", remote_host))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("Rejected request from {host} (possible directory traversal attack)")), + fmt::arg("host", remote_host))); } send_simple_response(req, HTTP_NOTFOUND); } @@ -529,9 +531,10 @@ void handle_request(struct evhttp_request* req, void* arg) if (server->is_anti_brute_force_enabled() && server->login_attempts_ >= server->settings().anti_brute_force_limit) { - tr_logAddWarn(fmt::format( - fmt::runtime(_("Rejected request from {host} (brute force protection active)")), - fmt::arg("host", remote_host))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("Rejected request from {host} (brute force protection active)")), + fmt::arg("host", remote_host))); send_simple_response(req, HttpErrorForbidden); return; } @@ -561,9 +564,10 @@ void handle_request(struct evhttp_request* req, void* arg) if (!is_authorized(server, evhttp_find_header(input_headers, "Authorization"))) { - tr_logAddWarn(fmt::format( - fmt::runtime(_("Rejected request from {host} (failed authentication)")), - fmt::arg("host", remote_host))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("Rejected request from {host} (failed authentication)")), + fmt::arg("host", remote_host))); evhttp_add_header(output_headers, "WWW-Authenticate", "Basic realm=\"" MY_REALM "\""); if (server->is_anti_brute_force_enabled()) { @@ -636,10 +640,11 @@ void handle_request(struct evhttp_request* req, void* arg) } else { - tr_logAddWarn(fmt::format( - fmt::runtime(_("Unknown URI from {host}: '{uri}'")), - fmt::arg("host", remote_host), - fmt::arg("uri", uri_sv))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("Unknown URI from {host}: '{uri}'")), + fmt::arg("host", remote_host), + fmt::arg("uri", uri_sv))); send_simple_response(req, HTTP_NOTFOUND, uri); } } @@ -655,9 +660,10 @@ bool bindUnixSocket( [[maybe_unused]] tr_mode_t socket_mode) { #ifdef _WIN32 - tr_logAddError(fmt::format( - _("Unix sockets are unsupported on Windows. Please change '{key}' in your settings."), - fmt::arg("key", tr_quark_get_string_view(TR_KEY_rpc_bind_address)))); + tr_logAddError( + fmt::format( + _("Unix sockets are unsupported on Windows. Please change '{key}' in your settings."), + fmt::arg("key", tr_quark_get_string_view(TR_KEY_rpc_bind_address)))); return false; #else auto addr = sockaddr_un{}; @@ -682,9 +688,10 @@ bool bindUnixSocket( if (chmod(addr.sun_path, socket_mode) != 0) { - tr_logAddWarn(fmt::format( - fmt::runtime(_("Couldn't set RPC socket mode to {mode:#o}, defaulting to 0755")), - fmt::arg("mode", socket_mode))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("Couldn't set RPC socket mode to {mode:#o}, defaulting to 0755")), + fmt::arg("mode", socket_mode))); } return evhttp_bind_listener(httpd, lev) != nullptr; @@ -797,22 +804,24 @@ void start_server(tr_rpc_server* server) return; } - tr_logAddError(fmt::format( - fmt::runtime(tr_ngettext( - "Couldn't bind to {address} after {count} attempt, giving up", - "Couldn't bind to {address} after {count} attempts, giving up", - ServerStartRetryCount)), - fmt::arg("address", addr_port_str), - fmt::arg("count", ServerStartRetryCount))); + tr_logAddError( + fmt::format( + fmt::runtime(tr_ngettext( + "Couldn't bind to {address} after {count} attempt, giving up", + "Couldn't bind to {address} after {count} attempts, giving up", + ServerStartRetryCount)), + fmt::arg("address", addr_port_str), + fmt::arg("count", ServerStartRetryCount))); } else { evhttp_set_gencb(httpd, handle_request, server); server->httpd.reset(httpd); - tr_logAddInfo(fmt::format( - fmt::runtime(_("Listening for RPC and Web requests on '{address}'")), - fmt::arg("address", addr_port_str))); + tr_logAddInfo( + fmt::format( + fmt::runtime(_("Listening for RPC and Web requests on '{address}'")), + fmt::arg("address", addr_port_str))); } rpc_server_start_retry_cancel(server); @@ -839,9 +848,10 @@ void stop_server(tr_rpc_server* server) unlink(address.c_str() + std::size(TrUnixSocketPrefix)); } - tr_logAddInfo(fmt::format( - fmt::runtime(_("Stopped listening for RPC and Web requests on '{address}'")), - fmt::arg("address", server->bind_address_->to_string(server->port())))); + tr_logAddInfo( + fmt::format( + fmt::runtime(_("Stopped listening for RPC and Web requests on '{address}'")), + fmt::arg("address", server->bind_address_->to_string(server->port())))); } void restart_server(tr_rpc_server* const server) @@ -983,11 +993,12 @@ void tr_rpc_server::load(Settings&& settings) if (!bind_address_->from_string(settings_.bind_address_str)) { // NOTE: bind_address_ is default initialized to INADDR_ANY - tr_logAddWarn(fmt::format( - fmt::runtime(_( - "The '{key}' setting is '{value}' but must be an IPv4 or IPv6 address or a Unix socket path. Using default value '0.0.0.0'")), - fmt::arg("key", tr_quark_get_string_view(TR_KEY_rpc_bind_address)), - fmt::arg("value", settings_.bind_address_str))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_( + "The '{key}' setting is '{value}' but must be an IPv4 or IPv6 address or a Unix socket path. Using default value '0.0.0.0'")), + fmt::arg("key", tr_quark_get_string_view(TR_KEY_rpc_bind_address)), + fmt::arg("value", settings_.bind_address_str))); } if (bind_address_->is_unix_addr()) diff --git a/libtransmission/rpcimpl.cc b/libtransmission/rpcimpl.cc index 9227f8dd5b..9c56b97624 100644 --- a/libtransmission/rpcimpl.cc +++ b/libtransmission/rpcimpl.cc @@ -1771,11 +1771,12 @@ void blocklistUpdate( DoneCb&& done_cb, struct tr_rpc_idle_data* idle_data) { - session->fetch({ - session->blocklistUrl(), - [cb = std::move(done_cb)](tr_web::FetchResponse const& r) { onBlocklistFetched(r, cb); }, - idle_data, - }); + session->fetch( + { + session->blocklistUrl(), + [cb = std::move(done_cb)](tr_web::FetchResponse const& r) { onBlocklistFetched(r, cb); }, + idle_data, + }); } // --- @@ -1838,11 +1839,12 @@ void onMetadataFetched(tr_web::FetchResponse const& web_response, DoneCb const& auto const& [status, body, primary_ip, did_connect, did_timeout, user_data] = web_response; auto* data = static_cast(user_data); - tr_logAddTrace(fmt::format( - "torrentAdd: HTTP response code was {} ({}); response length was {} bytes", - status, - tr_webGetResponseStr(status), - std::size(body))); + tr_logAddTrace( + fmt::format( + "torrentAdd: HTTP response code was {} ({}); response length was {} bytes", + status, + tr_webGetResponseStr(status), + std::size(body))); if (status == 200 || status == 221) /* http or ftp success.. */ { diff --git a/libtransmission/session-id.cc b/libtransmission/session-id.cc index 3a25afe3df..71f8398e10 100644 --- a/libtransmission/session-id.cc +++ b/libtransmission/session-id.cc @@ -64,11 +64,12 @@ tr_sys_file_t create_lockfile(std::string_view session_id) if (error) { - tr_logAddWarn(fmt::format( - fmt::runtime(_("Couldn't create '{path}': {error} ({error_code})")), - fmt::arg("path", lockfile_path), - fmt::arg("error", error.message()), - fmt::arg("error_code", error.code()))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("Couldn't create '{path}': {error} ({error_code})")), + fmt::arg("path", lockfile_path), + fmt::arg("error", error.message()), + fmt::arg("error_code", error.code()))); } return lockfile_fd; @@ -146,11 +147,12 @@ bool tr_session_id::is_local(std::string_view session_id) noexcept if (error) { - tr_logAddWarn(fmt::format( - fmt::runtime(_("Couldn't open session lock file '{path}': {error} ({error_code})")), - fmt::arg("path", lockfile_path), - fmt::arg("error", error.message()), - fmt::arg("error_code", error.code()))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("Couldn't open session lock file '{path}': {error} ({error_code})")), + fmt::arg("path", lockfile_path), + fmt::arg("error", error.message()), + fmt::arg("error_code", error.code()))); } return is_local; diff --git a/libtransmission/session-thread.h b/libtransmission/session-thread.h index 7185f8d03f..dbe86c000c 100644 --- a/libtransmission/session-thread.h +++ b/libtransmission/session-thread.h @@ -35,10 +35,11 @@ public: void queue(Func&& func, Args&&... args) { // TODO(tearfur): Use C++20 P0780R2, GCC 9, clang 9 - queue(std::function{ - [func = std::forward(func), args = std::make_tuple(std::forward(args)...)]() - { std::apply(std::move(func), std::move(args)); }, - }); + queue( + std::function{ + [func = std::forward(func), args = std::make_tuple(std::forward(args)...)]() + { std::apply(std::move(func), std::move(args)); }, + }); } template diff --git a/libtransmission/session.cc b/libtransmission/session.cc index fc346ad035..b4fb04e5e1 100644 --- a/libtransmission/session.cc +++ b/libtransmission/session.cc @@ -417,9 +417,10 @@ tr_session::BoundSocket::BoundSocket( return; } - tr_logAddInfo(fmt::format( - fmt::runtime(_("Listening to incoming peer connections on {hostport}")), - fmt::arg("hostport", tr_socket_address::display_name(addr, port)))); + tr_logAddInfo( + fmt::format( + fmt::runtime(_("Listening to incoming peer connections on {hostport}")), + fmt::arg("hostport", tr_socket_address::display_name(addr, port)))); event_add(ev_.get(), nullptr); } @@ -1505,9 +1506,10 @@ void session_load_torrents(tr_session* session, tr_ctor* ctor, std::promiseset_value(n_torrents); diff --git a/libtransmission/torrent.cc b/libtransmission/torrent.cc index 64a05c09e0..56bfd1d3e6 100644 --- a/libtransmission/torrent.cc +++ b/libtransmission/torrent.cc @@ -134,12 +134,13 @@ bool tr_torrentSetMetainfoFromFile(tr_torrent* tor, tr_torrent_metainfo const* m tor->use_metainfo_from_file(metainfo, filename, &error); if (error) { - tor->error().set_local_error(fmt::format( - fmt::runtime(_("Couldn't use metainfo from '{path}' for '{magnet}': {error} ({error_code})")), - fmt::arg("path", filename), - fmt::arg("magnet", tor->magnet()), - fmt::arg("error", error.message()), - fmt::arg("error_code", error.code()))); + tor->error().set_local_error( + fmt::format( + fmt::runtime(_("Couldn't use metainfo from '{path}' for '{magnet}': {error} ({error_code})")), + fmt::arg("path", filename), + fmt::arg("magnet", tor->magnet()), + fmt::arg("error", error.message()), + fmt::arg("error_code", error.code()))); return false; } @@ -719,10 +720,11 @@ void tr_torrentRemoveInSessionThread( ok = false; tor->is_deleting_ = false; - tor->error().set_local_error(fmt::format( - fmt::runtime(_("Couldn't remove all torrent files: {error} ({error_code})")), - fmt::arg("error", error.message()), - fmt::arg("error_code", error.code()))); + tor->error().set_local_error( + fmt::format( + fmt::runtime(_("Couldn't remove all torrent files: {error} ({error_code})")), + fmt::arg("error", error.message()), + fmt::arg("error_code", error.code()))); tr_torrentStop(tor); } } @@ -1004,11 +1006,12 @@ void tr_torrent::init(tr_ctor const& ctor) if (error) { - this->error().set_local_error(fmt::format( - fmt::runtime(_("Couldn't save '{path}': {error} ({error_code})")), - fmt::arg("path", file_path), - fmt::arg("error", error.message()), - fmt::arg("error_code", error.code()))); + this->error().set_local_error( + fmt::format( + fmt::runtime(_("Couldn't save '{path}': {error} ({error_code})")), + fmt::arg("path", file_path), + fmt::arg("error", error.message()), + fmt::arg("error_code", error.code()))); } } @@ -1102,12 +1105,13 @@ void tr_torrent::set_location_in_session_thread(std::string_view const path, boo ok = files().move(current_dir(), path, name(), &error); if (error) { - this->error().set_local_error(fmt::format( - fmt::runtime(_("Couldn't move '{old_path}' to '{path}': {error} ({error_code})")), - fmt::arg("old_path", current_dir()), - fmt::arg("path", path), - fmt::arg("error", error.message()), - fmt::arg("error_code", error.code()))); + this->error().set_local_error( + fmt::format( + fmt::runtime(_("Couldn't move '{old_path}' to '{path}': {error} ({error_code})")), + fmt::arg("old_path", current_dir()), + fmt::arg("path", path), + fmt::arg("error", error.message()), + fmt::arg("error_code", error.code()))); tr_torrentStop(this); } } @@ -2000,11 +2004,12 @@ bool tr_torrent::set_announce_list(tr_announce_list announce_list) if (save_error.has_value()) { - error().set_local_error(fmt::format( - fmt::runtime(_("Couldn't save '{path}': {error} ({error_code})")), - fmt::arg("path", filename), - fmt::arg("error", save_error.message()), - fmt::arg("error_code", save_error.code()))); + error().set_local_error( + fmt::format( + fmt::runtime(_("Couldn't save '{path}': {error} ({error_code})")), + fmt::arg("path", filename), + fmt::arg("error", save_error.message()), + fmt::arg("error_code", save_error.code()))); return false; } diff --git a/libtransmission/torrent.h b/libtransmission/torrent.h index 17740bc5e2..12703ed286 100644 --- a/libtransmission/torrent.h +++ b/libtransmission/torrent.h @@ -1253,10 +1253,7 @@ private: constexpr void bump_date_changed(time_t when) { - if (date_changed_ < when) - { - date_changed_ = when; - } + date_changed_ = std::max(date_changed_, when); } void set_verify_state(VerifyState state); diff --git a/libtransmission/tr-dht.cc b/libtransmission/tr-dht.cc index 10284793b1..a13cb27803 100644 --- a/libtransmission/tr-dht.cc +++ b/libtransmission/tr-dht.cc @@ -549,10 +549,11 @@ private: if (line_stream.bad() || std::empty(addrstr)) { - tr_logAddWarn(fmt::format( - fmt::runtime(_("Couldn't parse '{filename}' line: '{line}'")), - fmt::arg("filename", filename), - fmt::arg("line", line))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("Couldn't parse '{filename}' line: '{line}'")), + fmt::arg("filename", filename), + fmt::arg("line", line))); } else { @@ -573,12 +574,13 @@ private: addrinfo* info = nullptr; if (int const rc = getaddrinfo(name, port_str.c_str(), &hints, &info); rc != 0) { - tr_logAddWarn(fmt::format( - fmt::runtime(_("Couldn't look up '{address}:{port}': {error} ({error_code})")), - fmt::arg("address", name), - fmt::arg("port", port_in.host()), - fmt::arg("error", gai_strerror(rc)), - fmt::arg("error_code", rc))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("Couldn't look up '{address}:{port}': {error} ({error_code})")), + fmt::arg("address", name), + fmt::arg("port", port_in.host()), + fmt::arg("error", gai_strerror(rc)), + fmt::arg("error_code", rc))); return; } diff --git a/libtransmission/tr-lpd.cc b/libtransmission/tr-lpd.cc index c6ce69ea28..f21bc75b4c 100644 --- a/libtransmission/tr-lpd.cc +++ b/libtransmission/tr-lpd.cc @@ -266,11 +266,12 @@ private: auto const err = sockerrno; tr_net_close_socket(mcast_sockets_[TR_AF_INET]); mcast_sockets_[TR_AF_INET] = TR_BAD_SOCKET; - tr_logAddWarn(fmt::format( - fmt::runtime(_("Couldn't initialize {ip_protocol} LPD: {error} ({error_code})")), - fmt::arg("ip_protocol", tr_ip_protocol_to_sv(TR_AF_INET)), - fmt::arg("error", tr_strerror(err)), - fmt::arg("error_code", err))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("Couldn't initialize {ip_protocol} LPD: {error} ({error_code})")), + fmt::arg("ip_protocol", tr_ip_protocol_to_sv(TR_AF_INET)), + fmt::arg("error", tr_strerror(err)), + fmt::arg("error_code", err))); --n_success; } @@ -279,11 +280,12 @@ private: auto const err = sockerrno; tr_net_close_socket(mcast_sockets_[TR_AF_INET6]); mcast_sockets_[TR_AF_INET6] = TR_BAD_SOCKET; - tr_logAddWarn(fmt::format( - fmt::runtime(_("Couldn't initialize {ip_protocol} LPD: {error} ({error_code})")), - fmt::arg("ip_protocol", tr_ip_protocol_to_sv(TR_AF_INET6)), - fmt::arg("error", tr_strerror(err)), - fmt::arg("error_code", err))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("Couldn't initialize {ip_protocol} LPD: {error} ({error_code})")), + fmt::arg("ip_protocol", tr_ip_protocol_to_sv(TR_AF_INET6)), + fmt::arg("error", tr_strerror(err)), + fmt::arg("error_code", err))); --n_success; } @@ -604,10 +606,11 @@ private: { if (messages_received_since_upkeep_ > MaxIncomingPerUpkeep) { - tr_logAddTrace(fmt::format( - "Dropped {} announces in the last interval (max. {} allowed)", - messages_received_since_upkeep_ - MaxIncomingPerUpkeep, - MaxIncomingPerUpkeep)); + tr_logAddTrace( + fmt::format( + "Dropped {} announces in the last interval (max. {} allowed)", + messages_received_since_upkeep_ - MaxIncomingPerUpkeep, + MaxIncomingPerUpkeep)); } messages_received_since_upkeep_ = 0; diff --git a/libtransmission/tr-udp.cc b/libtransmission/tr-udp.cc index 92f0e72bfd..35c1a8e870 100644 --- a/libtransmission/tr-udp.cc +++ b/libtransmission/tr-udp.cc @@ -144,11 +144,12 @@ void event_callback(evutil_socket_t s, [[maybe_unused]] short type, void* vsessi } else { - tr_logAddTrace(fmt::format( - "{} Unexpected UDP packet... len {} [{}]", - from_str(), - n_read, - tr_base64_encode({ reinterpret_cast(std::data(buf)), static_cast(n_read) }))); + tr_logAddTrace( + fmt::format( + "{} Unexpected UDP packet... len {} [{}]", + from_str(), + n_read, + tr_base64_encode({ reinterpret_cast(std::data(buf)), static_cast(n_read) }))); } } } @@ -180,22 +181,24 @@ tr_session::tr_udp_core::tr_udp_core(tr_session& session, tr_port udp_port) if (evutil_make_socket_nonblocking(sock) != 0) { auto const error_code = errno; - tr_logAddWarn(fmt::format( - fmt::runtime(_("Couldn't make IPv4 socket non-blocking {address}: {error} ({error_code})")), - fmt::arg("address", tr_socket_address::display_name(addr, udp_port_)), - fmt::arg("error", tr_strerror(error_code)), - fmt::arg("error_code", error_code))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("Couldn't make IPv4 socket non-blocking {address}: {error} ({error_code})")), + fmt::arg("address", tr_socket_address::display_name(addr, udp_port_)), + fmt::arg("error", tr_strerror(error_code)), + fmt::arg("error_code", error_code))); tr_net_close_socket(sock); } else if (bind(sock, reinterpret_cast(&ss), sslen) != 0) { auto const error_code = errno; - tr_logAddWarn(fmt::format( - fmt::runtime(_("Couldn't bind IPv4 socket {address}: {error} ({error_code})")), - fmt::arg("address", tr_socket_address::display_name(addr, udp_port_)), - fmt::arg("error", tr_strerror(error_code)), - fmt::arg("error_code", error_code))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("Couldn't bind IPv4 socket {address}: {error} ({error_code})")), + fmt::arg("address", tr_socket_address::display_name(addr, udp_port_)), + fmt::arg("error", tr_strerror(error_code)), + fmt::arg("error_code", error_code))); tr_net_close_socket(sock); } @@ -225,22 +228,24 @@ tr_session::tr_udp_core::tr_udp_core(tr_session& session, tr_port udp_port) if (evutil_make_socket_nonblocking(sock) != 0) { auto const error_code = errno; - tr_logAddWarn(fmt::format( - fmt::runtime(_("Couldn't make IPv6 socket non-blocking {address}: {error} ({error_code})")), - fmt::arg("address", tr_socket_address::display_name(addr, udp_port_)), - fmt::arg("error", tr_strerror(error_code)), - fmt::arg("error_code", error_code))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("Couldn't make IPv6 socket non-blocking {address}: {error} ({error_code})")), + fmt::arg("address", tr_socket_address::display_name(addr, udp_port_)), + fmt::arg("error", tr_strerror(error_code)), + fmt::arg("error_code", error_code))); tr_net_close_socket(sock); } else if (bind(sock, reinterpret_cast(&ss), sslen) != 0) { auto const error_code = errno; - tr_logAddWarn(fmt::format( - fmt::runtime(_("Couldn't bind IPv6 socket {address}: {error} ({error_code})")), - fmt::arg("address", tr_socket_address::display_name(addr, udp_port_)), - fmt::arg("error", tr_strerror(error_code)), - fmt::arg("error_code", error_code))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("Couldn't bind IPv6 socket {address}: {error} ({error_code})")), + fmt::arg("address", tr_socket_address::display_name(addr, udp_port_)), + fmt::arg("error", tr_strerror(error_code)), + fmt::arg("error_code", error_code))); tr_net_close_socket(sock); } @@ -310,9 +315,10 @@ void tr_session::tr_udp_core::sendto(void const* buf, size_t buflen, struct sock display_name = addrport->display_name(); } - tr_logAddWarn(fmt::format( - "Couldn't send to {address}: {errno} ({error})", - fmt::arg("address", display_name), - fmt::arg("errno", errno), - fmt::arg("error", tr_strerror(errno)))); + tr_logAddWarn( + fmt::format( + "Couldn't send to {address}: {errno} ({error})", + fmt::arg("address", display_name), + fmt::arg("errno", errno), + fmt::arg("error", tr_strerror(errno)))); } diff --git a/libtransmission/utils.cc b/libtransmission/utils.cc index 050a39b6d5..79877a5697 100644 --- a/libtransmission/utils.cc +++ b/libtransmission/utils.cc @@ -134,11 +134,12 @@ bool tr_file_read(std::string_view filename, std::vector& contents, tr_err auto const info = tr_sys_path_get_info(szfilename, 0, error); if (*error) { - tr_logAddError(fmt::format( - fmt::runtime(_("Couldn't read '{path}': {error} ({error_code})")), - fmt::arg("path", filename), - fmt::arg("error", error->message()), - fmt::arg("error_code", error->code()))); + tr_logAddError( + fmt::format( + fmt::runtime(_("Couldn't read '{path}': {error} ({error_code})")), + fmt::arg("path", filename), + fmt::arg("error", error->message()), + fmt::arg("error_code", error->code()))); return false; } @@ -153,22 +154,24 @@ bool tr_file_read(std::string_view filename, std::vector& contents, tr_err auto const fd = tr_sys_file_open(szfilename, TR_SYS_FILE_READ | TR_SYS_FILE_SEQUENTIAL, 0, error); if (fd == TR_BAD_SYS_FILE) { - tr_logAddError(fmt::format( - fmt::runtime(_("Couldn't read '{path}': {error} ({error_code})")), - fmt::arg("path", filename), - fmt::arg("error", error->message()), - fmt::arg("error_code", error->code()))); + tr_logAddError( + fmt::format( + fmt::runtime(_("Couldn't read '{path}': {error} ({error_code})")), + fmt::arg("path", filename), + fmt::arg("error", error->message()), + fmt::arg("error_code", error->code()))); return false; } contents.resize(info->size); if (!tr_sys_file_read(fd, std::data(contents), info->size, nullptr, error)) { - tr_logAddError(fmt::format( - fmt::runtime(_("Couldn't read '{path}': {error} ({error_code})")), - fmt::arg("path", filename), - fmt::arg("error", error->message()), - fmt::arg("error_code", error->code()))); + tr_logAddError( + fmt::format( + fmt::runtime(_("Couldn't read '{path}': {error} ({error_code})")), + fmt::arg("path", filename), + fmt::arg("error", error->message()), + fmt::arg("error_code", error->code()))); tr_sys_file_close(fd); return false; } @@ -632,11 +635,12 @@ bool tr_file_move(std::string_view oldpath_in, std::string_view newpath_in, bool if (auto log_error = tr_error{}; !tr_sys_path_remove(oldpath, &log_error)) { - tr_logAddError(fmt::format( - fmt::runtime(_("Couldn't remove '{path}': {error} ({error_code})")), - fmt::arg("path", oldpath), - fmt::arg("error", log_error.message()), - fmt::arg("error_code", log_error.code()))); + tr_logAddError( + fmt::format( + fmt::runtime(_("Couldn't remove '{path}': {error} ({error_code})")), + fmt::arg("path", oldpath), + fmt::arg("error", log_error.message()), + fmt::arg("error_code", log_error.code()))); } return true; diff --git a/libtransmission/variant.cc b/libtransmission/variant.cc index 5c2475eb8f..c37bb561c6 100644 --- a/libtransmission/variant.cc +++ b/libtransmission/variant.cc @@ -872,11 +872,12 @@ bool tr_variant_serde::to_file(tr_variant const& var, std::string_view filename) if (error_) { - tr_logAddError(fmt::format( - fmt::runtime(_("Couldn't save '{path}': {error} ({error_code})")), - fmt::arg("path", filename), - fmt::arg("error", error_.message()), - fmt::arg("error_code", error_.code()))); + tr_logAddError( + fmt::format( + fmt::runtime(_("Couldn't save '{path}': {error} ({error_code})")), + fmt::arg("path", filename), + fmt::arg("error", error_.message()), + fmt::arg("error_code", error_.code()))); return false; } diff --git a/libtransmission/watchdir-inotify.cc b/libtransmission/watchdir-inotify.cc index 2bedcd323b..b532080d1b 100644 --- a/libtransmission/watchdir-inotify.cc +++ b/libtransmission/watchdir-inotify.cc @@ -82,11 +82,12 @@ private: if (infd_ == -1) { auto const error_code = errno; - tr_logAddError(fmt::format( - fmt::runtime(_("Couldn't watch '{path}': {error} ({error_code})")), - fmt::arg("path", dirname()), - fmt::arg("error", tr_strerror(error_code)), - fmt::arg("error_code", error_code))); + tr_logAddError( + fmt::format( + fmt::runtime(_("Couldn't watch '{path}': {error} ({error_code})")), + fmt::arg("path", dirname()), + fmt::arg("error", tr_strerror(error_code)), + fmt::arg("error_code", error_code))); return; } @@ -94,11 +95,12 @@ private: if (inwd_ == -1) { auto const error_code = errno; - tr_logAddError(fmt::format( - fmt::runtime(_("Couldn't watch '{path}': {error} ({error_code})")), - fmt::arg("path", dirname()), - fmt::arg("error", tr_strerror(error_code)), - fmt::arg("error_code", error_code))); + tr_logAddError( + fmt::format( + fmt::runtime(_("Couldn't watch '{path}': {error} ({error_code})")), + fmt::arg("path", dirname()), + fmt::arg("error", tr_strerror(error_code)), + fmt::arg("error_code", error_code))); return; } @@ -106,11 +108,12 @@ private: if (event_ == nullptr) { auto const error_code = errno; - tr_logAddError(fmt::format( - fmt::runtime(_("Couldn't watch '{path}': {error} ({error_code})")), - fmt::arg("path", dirname()), - fmt::arg("error", tr_strerror(error_code)), - fmt::arg("error_code", error_code))); + tr_logAddError( + fmt::format( + fmt::runtime(_("Couldn't watch '{path}': {error} ({error_code})")), + fmt::arg("path", dirname()), + fmt::arg("error", tr_strerror(error_code)), + fmt::arg("error_code", error_code))); return; } @@ -138,19 +141,21 @@ private: if (nread == (size_t)-1) { auto const error_code = errno; - tr_logAddError(fmt::format( - fmt::runtime(_("Couldn't read event: {error} ({error_code})")), - fmt::arg("error", tr_strerror(error_code)), - fmt::arg("error_code", error_code))); + tr_logAddError( + fmt::format( + fmt::runtime(_("Couldn't read event: {error} ({error_code})")), + fmt::arg("error", tr_strerror(error_code)), + fmt::arg("error_code", error_code))); break; } if (nread != sizeof(ev)) { - tr_logAddError(fmt::format( - fmt::runtime(_("Couldn't read event: expected {expected_size}, got {actual_size}")), - fmt::arg("expected_size", sizeof(ev)), - fmt::arg("actual_size", nread))); + tr_logAddError( + fmt::format( + fmt::runtime(_("Couldn't read event: expected {expected_size}, got {actual_size}")), + fmt::arg("expected_size", sizeof(ev)), + fmt::arg("actual_size", nread))); break; } @@ -164,19 +169,21 @@ private: if (nread == static_cast(-1)) { auto const error_code = errno; - tr_logAddError(fmt::format( - fmt::runtime(_("Couldn't read filename: {error} ({error_code})")), - fmt::arg("error", tr_strerror(error_code)), - fmt::arg("error_code", error_code))); + tr_logAddError( + fmt::format( + fmt::runtime(_("Couldn't read filename: {error} ({error_code})")), + fmt::arg("error", tr_strerror(error_code)), + fmt::arg("error_code", error_code))); break; } if (nread != ev.len) { - tr_logAddError(fmt::format( - fmt::runtime(_("Couldn't read filename: expected {expected_size}, got {actual_size}")), - fmt::arg("expected_size", sizeof(ev)), - fmt::arg("actual_size", nread))); + tr_logAddError( + fmt::format( + fmt::runtime(_("Couldn't read filename: expected {expected_size}, got {actual_size}")), + fmt::arg("expected_size", sizeof(ev)), + fmt::arg("actual_size", nread))); break; } diff --git a/libtransmission/watchdir-kqueue.cc b/libtransmission/watchdir-kqueue.cc index 3771cc47ff..c8afa92596 100644 --- a/libtransmission/watchdir-kqueue.cc +++ b/libtransmission/watchdir-kqueue.cc @@ -71,10 +71,11 @@ private: if (kq_ == -1) { auto const error_code = errno; - tr_logAddError(fmt::format( - fmt::runtime(_("Couldn't watch '{path}': {error} ({error_code})")), - fmt::arg("error", tr_strerror(error_code)), - fmt::arg("error_code", error_code))); + tr_logAddError( + fmt::format( + fmt::runtime(_("Couldn't watch '{path}': {error} ({error_code})")), + fmt::arg("error", tr_strerror(error_code)), + fmt::arg("error_code", error_code))); return; } @@ -84,11 +85,12 @@ private: if (dirfd_ == -1) { auto const error_code = errno; - tr_logAddError(fmt::format( - fmt::runtime(_("Couldn't watch '{path}': {error} ({error_code})")), - fmt::arg("path", dirname()), - fmt::arg("error", tr_strerror(error_code)), - fmt::arg("error_code", error_code))); + tr_logAddError( + fmt::format( + fmt::runtime(_("Couldn't watch '{path}': {error} ({error_code})")), + fmt::arg("path", dirname()), + fmt::arg("error", tr_strerror(error_code)), + fmt::arg("error_code", error_code))); return; } @@ -99,11 +101,12 @@ private: if (kevent(kq_, &ke, 1, nullptr, 0, nullptr) == -1) { auto const error_code = errno; - tr_logAddError(fmt::format( - fmt::runtime(_("Couldn't watch '{path}': {error} ({error_code})")), - fmt::arg("path", dirname()), - fmt::arg("error", tr_strerror(error_code)), - fmt::arg("error_code", error_code))); + tr_logAddError( + fmt::format( + fmt::runtime(_("Couldn't watch '{path}': {error} ({error_code})")), + fmt::arg("path", dirname()), + fmt::arg("error", tr_strerror(error_code)), + fmt::arg("error_code", error_code))); return; } @@ -112,20 +115,22 @@ private: if (!event_) { auto const error_code = errno; - tr_logAddError(fmt::format( - fmt::runtime(_("Couldn't create event: {error} ({error_code})")), - fmt::arg("error", tr_strerror(error_code)), - fmt::arg("error_code", error_code))); + tr_logAddError( + fmt::format( + fmt::runtime(_("Couldn't create event: {error} ({error_code})")), + fmt::arg("error", tr_strerror(error_code)), + fmt::arg("error_code", error_code))); return; } if (event_add(event_.get(), nullptr) == -1) { auto const error_code = errno; - tr_logAddError(fmt::format( - fmt::runtime(_("Couldn't add event: {error} ({error_code})")), - fmt::arg("error", tr_strerror(error_code)), - fmt::arg("error_code", error_code))); + tr_logAddError( + fmt::format( + fmt::runtime(_("Couldn't add event: {error} ({error_code})")), + fmt::arg("error", tr_strerror(error_code)), + fmt::arg("error_code", error_code))); return; } } @@ -142,10 +147,11 @@ private: if (kevent(kq_, nullptr, 0, &ke, 1, &ts) == -1) { auto const error_code = errno; - tr_logAddError(fmt::format( - fmt::runtime(_("Couldn't read event: {error} ({error_code})")), - fmt::arg("error", tr_strerror(error_code)), - fmt::arg("error_code", error_code))); + tr_logAddError( + fmt::format( + fmt::runtime(_("Couldn't read event: {error} ({error_code})")), + fmt::arg("error", tr_strerror(error_code)), + fmt::arg("error_code", error_code))); return; } diff --git a/libtransmission/watchdir-win32.cc b/libtransmission/watchdir-win32.cc index cbb9c62e05..8f181f0bd2 100644 --- a/libtransmission/watchdir-win32.cc +++ b/libtransmission/watchdir-win32.cc @@ -180,10 +180,11 @@ private: if (evutil_socketpair(AF_INET, SOCK_STREAM, 0, std::data(notify_pipe_)) == -1) { auto const error_code = errno; - tr_logAddError(fmt::format( - _("Couldn't create pipe: {error} ({error_code})"), - fmt::arg("error", tr_strerror(error_code)), - fmt::arg("error_code", error_code))); + tr_logAddError( + fmt::format( + _("Couldn't create pipe: {error} ({error_code})"), + fmt::arg("error", tr_strerror(error_code)), + fmt::arg("error_code", error_code))); return; } @@ -191,10 +192,11 @@ private: if (event_ == nullptr) { auto const error_code = errno; - tr_logAddError(fmt::format( - _("Couldn't create event: {error} ({error_code})"), - fmt::arg("error", tr_strerror(error_code)), - fmt::arg("error_code", error_code))); + tr_logAddError( + fmt::format( + _("Couldn't create event: {error} ({error_code})"), + fmt::arg("error", tr_strerror(error_code)), + fmt::arg("error_code", error_code))); return; } @@ -290,19 +292,21 @@ private: if (nread == static_cast(-1)) { auto const error_code = errno; - tr_logAddError(fmt::format( - _("Couldn't read event: {error} ({error_code})"), - fmt::arg("error", tr_strerror(error_code)), - fmt::arg("error_code", error_code))); + tr_logAddError( + fmt::format( + _("Couldn't read event: {error} ({error_code})"), + fmt::arg("error", tr_strerror(error_code)), + fmt::arg("error_code", error_code))); break; } if (nread != header_size) { - tr_logAddError(fmt::format( - _("Couldn't read event: expected {expected_size}, got {actual_size}"), - fmt::arg("expected_size", header_size), - fmt::arg("actual_size", nread))); + tr_logAddError( + fmt::format( + _("Couldn't read event: expected {expected_size}, got {actual_size}"), + fmt::arg("expected_size", header_size), + fmt::arg("actual_size", nread))); break; } @@ -324,19 +328,21 @@ private: if (nread == static_cast(-1)) { auto const error_code = errno; - tr_logAddError(fmt::format( - _("Couldn't read filename: {error} ({error_code})"), - fmt::arg("error", tr_strerror(error_code)), - fmt::arg("error_code", error_code))); + tr_logAddError( + fmt::format( + _("Couldn't read filename: {error} ({error_code})"), + fmt::arg("error", tr_strerror(error_code)), + fmt::arg("error_code", error_code))); break; } if (nread != nleft) { - tr_logAddError(fmt::format( - _("Couldn't read filename: expected {expected_size}, got {actual_size}"), - fmt::arg("expected_size", nleft), - fmt::arg("actual_size", nread))); + tr_logAddError( + fmt::format( + _("Couldn't read filename: expected {expected_size}, got {actual_size}"), + fmt::arg("expected_size", nleft), + fmt::arg("actual_size", nread))); break; } diff --git a/libtransmission/watchdir.cc b/libtransmission/watchdir.cc index 181174adad..76f4158926 100644 --- a/libtransmission/watchdir.cc +++ b/libtransmission/watchdir.cc @@ -48,11 +48,12 @@ namespace auto const info = tr_sys_path_get_info(path, 0, &error); if (error && !tr_error_is_enoent(error.code())) { - tr_logAddWarn(fmt::format( - fmt::runtime(_("Skipping '{path}': {error} ({error_code})")), - fmt::arg("path", path), - fmt::arg("error", error.message()), - fmt::arg("error_code", error.code()))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("Skipping '{path}': {error} ({error_code})")), + fmt::arg("path", path), + fmt::arg("error", error.message()), + fmt::arg("error_code", error.code()))); } return info && info->isFile(); @@ -114,11 +115,12 @@ void BaseWatchdir::scan() if (error) { - tr_logAddWarn(fmt::format( - fmt::runtime(_("Couldn't read '{path}': {error} ({error_code})")), - fmt::arg("path", dirname()), - fmt::arg("error", error.message()), - fmt::arg("error_code", error.code()))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("Couldn't read '{path}': {error} ({error_code})")), + fmt::arg("path", dirname()), + fmt::arg("error", error.message()), + fmt::arg("error_code", error.code()))); } } diff --git a/libtransmission/web.cc b/libtransmission/web.cc index 1df0af2d13..cc836d05f8 100644 --- a/libtransmission/web.cc +++ b/libtransmission/web.cc @@ -168,20 +168,23 @@ public: if (curl_version_num == 0x080901) { tr_logAddWarn(_("Consider upgrading your curl installation.")); - tr_logAddWarn(fmt::format( - fmt::runtime(_("curl {curl_version} is prone to SIGPIPE crashes. {details_url}")), - fmt::arg("curl_version", "8.9.1"), - fmt::arg("details_url", "https://github.com/transmission/transmission/issues/7035"))); + tr_logAddWarn( + fmt::format( + fmt::runtime(_("curl {curl_version} is prone to SIGPIPE crashes. {details_url}")), + fmt::arg("curl_version", "8.9.1"), + fmt::arg("details_url", "https://github.com/transmission/transmission/issues/7035"))); } if (curl_version_num == 0x080B01) { tr_logAddWarn(_("Consider upgrading your curl installation.")); - tr_logAddWarn(fmt::format( - fmt::runtime(_("curl {curl_version} is prone to an eventfd double close vulnerability that might cause SIGABRT " - "crashes for the transmission-daemon systemd service. {details_url}")), - fmt::arg("curl_version", "8.11.1"), - fmt::arg("details_url", "https://curl.se/docs/CVE-2025-0665.html"))); + tr_logAddWarn( + fmt::format( + fmt::runtime( + _("curl {curl_version} is prone to an eventfd double close vulnerability that might cause SIGABRT " + "crashes for the transmission-daemon systemd service. {details_url}")), + fmt::arg("curl_version", "8.11.1"), + fmt::arg("details_url", "https://curl.se/docs/CVE-2025-0665.html"))); } if (auto bundle = tr_env_get_string("CURL_CA_BUNDLE"); !std::empty(bundle)) @@ -194,9 +197,10 @@ public: if (curl_ssl_verify) { auto const* bundle = std::empty(curl_ca_bundle) ? "none" : curl_ca_bundle.c_str(); - tr_logAddInfo(fmt::format( - fmt::runtime(_("Will verify tracker certs using envvar CURL_CA_BUNDLE: {bundle}")), - fmt::arg("bundle", bundle))); + tr_logAddInfo( + fmt::format( + fmt::runtime(_("Will verify tracker certs using envvar CURL_CA_BUNDLE: {bundle}")), + fmt::arg("bundle", bundle))); tr_logAddInfo(_("NB: this only works if you built against libcurl with openssl or gnutls, NOT nss")); tr_logAddInfo(_("NB: Invalid certs will appear as 'Could not connect to tracker' like many other errors")); } @@ -504,11 +508,13 @@ public: (void)curl_easy_getinfo(task->easy(), CURLINFO_RESPONSE_CODE, &code); if (code != NoResponseCode && code != PartialContentResponseCode) { - tr_logAddWarn(fmt::format( - fmt::runtime(_("Couldn't fetch '{url}': expected HTTP response code {expected_code}, got {actual_code}")), - fmt::arg("url", task->url()), - fmt::arg("expected_code", PartialContentResponseCode), - fmt::arg("actual_code", code))); + tr_logAddWarn( + fmt::format( + fmt::runtime( + _("Couldn't fetch '{url}': expected HTTP response code {expected_code}, got {actual_code}")), + fmt::arg("url", task->url()), + fmt::arg("expected_code", PartialContentResponseCode), + fmt::arg("actual_code", code))); // Tell curl to error out. Returning anything that's not // `bytes_used` signals an error and causes the transfer diff --git a/qt/.clang-tidy b/qt/.clang-tidy index b20b5e4a3d..9629bdb5eb 100644 --- a/qt/.clang-tidy +++ b/qt/.clang-tidy @@ -9,6 +9,7 @@ Checks: > -bugprone-easily-swappable-parameters, -bugprone-narrowing-conversions, cert-*, + -cert-int09-c, clang-analyzer-*, cppcoreguidelines-*, -cppcoreguidelines-avoid-const-or-ref-data-members, @@ -34,6 +35,7 @@ Checks: > performance-*, readability-*, -readability-convert-member-functions-to-static, + -readability-enum-initial-value, -readability-function-cognitive-complexity, -readability-identifier-length, -readability-implicit-bool-conversion, diff --git a/qt/AboutDialog.cc b/qt/AboutDialog.cc index 10bfc729a1..6cb13b8475 100644 --- a/qt/AboutDialog.cc +++ b/qt/AboutDialog.cc @@ -54,9 +54,10 @@ void AboutDialog::showCredits() QMessageBox::about( this, tr("Credits"), - QString::fromUtf8("Charles Kerr (Backend; Daemon; GTK+; Qt)\n" - "Mitchell Livingston (macOS)\n" - "Mike Gelfand\n")); + QString::fromUtf8( + "Charles Kerr (Backend; Daemon; GTK+; Qt)\n" + "Mitchell Livingston (macOS)\n" + "Mike Gelfand\n")); } void AboutDialog::showLicense() diff --git a/qt/Application.cc b/qt/Application.cc index 59b21ce067..072015702f 100644 --- a/qt/Application.cc +++ b/qt/Application.cc @@ -520,9 +520,10 @@ bool Application::notifyApp(QString const& title, QString const& body, QStringLi args.append(title); // summary args.append(body); // body args.append(actions); - args.append(QVariantMap{ { - std::make_pair(QStringLiteral("category"), QVariant{ QStringLiteral("transfer.complete") }), - } }); // hints + args.append( + QVariantMap{ { + std::make_pair(QStringLiteral("category"), QVariant{ QStringLiteral("transfer.complete") }), + } }); // hints args.append(static_cast(-1)); // use the default timeout period m.setArguments(args); QDBusReply const reply_msg = bus.call(m); diff --git a/tests/libtransmission/.clang-tidy b/tests/libtransmission/.clang-tidy index 95cbab806b..6b2af110ac 100644 --- a/tests/libtransmission/.clang-tidy +++ b/tests/libtransmission/.clang-tidy @@ -9,6 +9,7 @@ Checks: > -bugprone-narrowing-conversions, -bugprone-unchecked-optional-access, cert-*, + -cert-int09-c, clang-analyzer-optin*, cppcoreguidelines-*, -cppcoreguidelines-avoid-const-or-ref-data-members, @@ -32,6 +33,7 @@ Checks: > -modernize-use-trailing-return-type, performance-*, readability-*, + -readability-enum-initial-value, -readability-function-cognitive-complexity, -readability-identifier-length, -readability-magic-numbers, diff --git a/tests/libtransmission/announce-list-test.cc b/tests/libtransmission/announce-list-test.cc index 1fc2200bed..8e616c82cc 100644 --- a/tests/libtransmission/announce-list-test.cc +++ b/tests/libtransmission/announce-list-test.cc @@ -402,11 +402,12 @@ TEST_F(AnnounceListTest, save) EXPECT_EQ(original_tm.piece_count(), modified_tm.piece_count()); // test that the saved version has the updated announce list - EXPECT_TRUE(std::equal( - std::begin(announce_list), - std::end(announce_list), - std::begin(modified_tm.announce_list()), - std::end(modified_tm.announce_list()))); + EXPECT_TRUE( + std::equal( + std::begin(announce_list), + std::end(announce_list), + std::begin(modified_tm.announce_list()), + std::end(modified_tm.announce_list()))); // cleanup (void)std::remove(test_file.c_str()); diff --git a/tests/libtransmission/dht-test.cc b/tests/libtransmission/dht-test.cc index aa1a26ddfd..5aacc925cb 100644 --- a/tests/libtransmission/dht-test.cc +++ b/tests/libtransmission/dht-test.cc @@ -65,10 +65,7 @@ namespace bool waitFor(struct event_base* event_base, std::chrono::milliseconds msec) { - return libtransmission::test::waitFor( // - event_base, - []() { return false; }, - msec); + return libtransmission::test::waitFor(event_base, []() { return false; }, msec); } auto constexpr IdLength = size_t{ 20U }; @@ -604,10 +601,7 @@ TEST_F(DhtTest, usesBootstrapFile) auto const expected = tr_socket_address{ tr_address::from_string(BootstrapNodeName).value_or(tr_address{}), BootstrapNodePort }; auto& pinged = mediator.mock_dht_.pinged_; - waitFor( // - event_base_, - [&pinged]() { return !std::empty(pinged); }, - 5s); + waitFor(event_base_, [&pinged]() { return !std::empty(pinged); }, 5s); ASSERT_EQ(1U, std::size(pinged)); auto const [actual_addrport, time] = pinged.front(); EXPECT_EQ(expected.address(), actual_addrport.address()); diff --git a/tests/libtransmission/net-test.cc b/tests/libtransmission/net-test.cc index 4cf94b9072..66373ac6ea 100644 --- a/tests/libtransmission/net-test.cc +++ b/tests/libtransmission/net-test.cc @@ -82,10 +82,11 @@ TEST_F(NetTest, compact4) EXPECT_EQ(std::size(Compact4) - tr_port::CompactPortBytes, static_cast(out - std::data(buf))); EXPECT_TRUE( std::equal(std::data(Compact4), std::data(Compact4) + std::size(Compact4) - tr_port::CompactPortBytes, std::data(buf))); - EXPECT_TRUE(std::all_of( - std::begin(buf) + std::size(Compact4) - tr_port::CompactPortBytes, - std::end(buf), - [](std::byte const& byte) { return static_cast(byte) == 0U; })); + EXPECT_TRUE( + std::all_of( + std::begin(buf) + std::size(Compact4) - tr_port::CompactPortBytes, + std::end(buf), + [](std::byte const& byte) { return static_cast(byte) == 0U; })); /// sockaddr --> compact @@ -144,14 +145,16 @@ TEST_F(NetTest, compact6) out = std::data(compact6); out = addr.to_compact(out); EXPECT_EQ(std::size(Compact6) - tr_port::CompactPortBytes, static_cast(out - std::data(compact6))); - EXPECT_TRUE(std::equal( - std::data(Compact6), - std::data(Compact6) + std::size(Compact6) - tr_port::CompactPortBytes, - std::data(compact6))); - EXPECT_TRUE(std::all_of( - std::begin(compact6) + std::size(Compact6) - tr_port::CompactPortBytes, - std::end(compact6), - [](std::byte const& byte) { return static_cast(byte) == 0U; })); + EXPECT_TRUE( + std::equal( + std::data(Compact6), + std::data(Compact6) + std::size(Compact6) - tr_port::CompactPortBytes, + std::data(compact6))); + EXPECT_TRUE( + std::all_of( + std::begin(compact6) + std::size(Compact6) - tr_port::CompactPortBytes, + std::end(compact6), + [](std::byte const& byte) { return static_cast(byte) == 0U; })); /// sockaddr --> compact diff --git a/tests/libtransmission/timer-test.cc b/tests/libtransmission/timer-test.cc index 49d4954617..9f198dbad3 100644 --- a/tests/libtransmission/timer-test.cc +++ b/tests/libtransmission/timer-test.cc @@ -42,10 +42,7 @@ protected: void sleepMsec(std::chrono::milliseconds msec) { - EXPECT_FALSE(waitFor( // - evbase_.get(), - []() { return false; }, - msec)); + EXPECT_FALSE(waitFor(evbase_.get(), []() { return false; }, msec)); } static void expectTime( diff --git a/tests/libtransmission/tr-peer-info-test.cc b/tests/libtransmission/tr-peer-info-test.cc index 8f5a2d7eb3..5be4eac052 100644 --- a/tests/libtransmission/tr-peer-info-test.cc +++ b/tests/libtransmission/tr-peer-info-test.cc @@ -149,14 +149,13 @@ TEST_F(PeerInfoTest, updateCanonicalPriority) continue; } - auto const info = tr_peer_info{ *peer_sockaddr, - 0, - TR_PEER_FROM_PEX, - client_sockaddr->address(), - [&client_sockaddr] - { - return client_sockaddr->port(); - } }; + auto const info = tr_peer_info{ + *peer_sockaddr, + 0, + TR_PEER_FROM_PEX, + client_sockaddr->address(), + [&client_sockaddr] { return client_sockaddr->port(); }, + }; EXPECT_EQ(info.get_canonical_priority(), expected); } } diff --git a/utils/show.cc b/utils/show.cc index 2b86ae5743..aec01749c6 100644 --- a/utils/show.cc +++ b/utils/show.cc @@ -345,14 +345,15 @@ void doScrape(tr_torrent_metainfo const& metainfo) auto response_mutex = std::mutex{}; auto response_cv = std::condition_variable{}; auto lock = std::unique_lock(response_mutex); - web->fetch({ scrape_url, - [&response, &response_cv](tr_web::FetchResponse const& resp) - { - response = resp; - response_cv.notify_one(); - }, - nullptr, - TimeoutSecs }); + web->fetch( + { scrape_url, + [&response, &response_cv](tr_web::FetchResponse const& resp) + { + response = resp; + response_cv.notify_one(); + }, + nullptr, + TimeoutSecs }); response_cv.wait(lock); // check the response code