diff --git a/gtk/PathButton.cc b/gtk/PathButton.cc index ee840ecb0..f8cc49298 100644 --- a/gtk/PathButton.cc +++ b/gtk/PathButton.cc @@ -13,7 +13,7 @@ class PathButton::Impl { public: - Impl(PathButton& widget); + explicit Impl(PathButton& widget); TR_DISABLE_COPY_MOVE(Impl) diff --git a/gtk/Utils.cc b/gtk/Utils.cc index 483dc9ae3..283e14255 100644 --- a/gtk/Utils.cc +++ b/gtk/Utils.cc @@ -286,9 +286,9 @@ bool on_tree_view_button_pressed( if (context_menu_requested) { Gtk::TreeModel::Path path; - auto const selection = view.get_selection(); - if (view.get_path_at_pos((int)view_x, (int)view_y, path) && !selection->is_selected(path)) + if (auto const selection = view.get_selection(); + view.get_path_at_pos((int)view_x, (int)view_y, path) && !selection->is_selected(path)) { selection->unselect_all(); selection->select(path); @@ -707,8 +707,8 @@ void gtr_paste_clipboard_url_into_entry(Gtk::Entry& entry) { auto const process = [&entry](Glib::ustring const& text) { - auto const sv = tr_strvStrip(text.raw()); - if (!sv.empty() && (tr_urlIsValid(sv) || tr_magnet_metainfo{}.parseMagnet(sv))) + if (auto const sv = tr_strvStrip(text.raw()); + !sv.empty() && (tr_urlIsValid(sv) || tr_magnet_metainfo{}.parseMagnet(sv))) { entry.set_text(text); return true; diff --git a/libtransmission/dns-ev.h b/libtransmission/dns-ev.h index 29275104f..1750513bf 100644 --- a/libtransmission/dns-ev.h +++ b/libtransmission/dns-ev.h @@ -22,8 +22,6 @@ #include "dns.h" #include "utils.h" // for tr_strlower() -using namespace std::literals; - namespace libtransmission { @@ -107,7 +105,8 @@ public: } auto& request = requests_[key]; - auto const tag = next_tag_++; + auto const tag = next_tag_; + ++next_tag_; request.callbacks.emplace_back(tag, std::move(callback)); if (request.request == nullptr) { diff --git a/libtransmission/net.cc b/libtransmission/net.cc index 04fc3a8b1..3fe026878 100644 --- a/libtransmission/net.cc +++ b/libtransmission/net.cc @@ -321,7 +321,7 @@ struct tr_peer_socket tr_netOpenPeerSocket(tr_session* session, tr_address const auto const [source_addr, is_default_addr] = session->publicAddress(addr->type); auto const [source_sock, sourcelen] = source_addr.toSockaddr({}); - if (bind(s, (struct sockaddr*)&source_sock, sourcelen) == -1) + if (bind(s, reinterpret_cast(&source_sock), sourcelen) == -1) { tr_logAddWarn(fmt::format( _("Couldn't set source address {address} on {socket}: {error} ({error_code})"), @@ -334,7 +334,7 @@ struct tr_peer_socket tr_netOpenPeerSocket(tr_session* session, tr_address const } auto ret = tr_peer_socket{}; - if (connect(s, (struct sockaddr*)&sock, addrlen) == -1 && + if (connect(s, reinterpret_cast(&sock), addrlen) == -1 && #ifdef _WIN32 sockerrno != WSAEWOULDBLOCK && #endif diff --git a/libtransmission/net.h b/libtransmission/net.h index 30075408c..cfbf41928 100644 --- a/libtransmission/net.h +++ b/libtransmission/net.h @@ -142,7 +142,7 @@ public: } private: - constexpr tr_port(uint16_t hport) noexcept + explicit constexpr tr_port(uint16_t hport) noexcept : hport_{ hport } { } diff --git a/libtransmission/peer-io.cc b/libtransmission/peer-io.cc index db0fbad87..fa9930718 100644 --- a/libtransmission/peer-io.cc +++ b/libtransmission/peer-io.cc @@ -205,8 +205,7 @@ static void event_read_cb(evutil_socket_t fd, short /*event*/, void* vio) } tr_error* error = nullptr; - auto const res = io->inbuf.addSocket(fd, howmuch, &error); - if (res > 0) + if (auto const res = io->inbuf.addSocket(fd, howmuch, &error); res > 0) { io->setEnabled(dir, true); diff --git a/libtransmission/session.cc b/libtransmission/session.cc index c4eac5f84..4bb9a0170 100644 --- a/libtransmission/session.cc +++ b/libtransmission/session.cc @@ -290,7 +290,7 @@ static void acceptIncomingPeer(evutil_socket_t fd, short /*what*/, void* vsessio if (auto const incoming_info = tr_netAccept(session, fd); incoming_info) { - auto const [addr, port, sock] = *incoming_info; + auto const& [addr, port, sock] = *incoming_info; tr_logAddTrace(fmt::format("new incoming connection {} ({})", sock, addr.readable(port))); session->addIncoming(addr, port, tr_peer_socket_tcp_create(sock)); } diff --git a/libtransmission/session.h b/libtransmission/session.h index 6792cbbd4..8221e7d5f 100644 --- a/libtransmission/session.h +++ b/libtransmission/session.h @@ -143,7 +143,7 @@ private: class AnnouncerUdpMediator final : public tr_announcer_udp::Mediator { public: - AnnouncerUdpMediator(tr_session& session) + explicit AnnouncerUdpMediator(tr_session& session) : session_{ session } { } diff --git a/libtransmission/timer-ev.h b/libtransmission/timer-ev.h index 64295c4e2..7ed849dc2 100644 --- a/libtransmission/timer-ev.h +++ b/libtransmission/timer-ev.h @@ -20,7 +20,7 @@ namespace libtransmission class EvTimerMaker final : public TimerMaker { public: - EvTimerMaker(event_base* base) + explicit EvTimerMaker(event_base* base) : event_base_{ base } { } diff --git a/libtransmission/tr-buffer.h b/libtransmission/tr-buffer.h index bfe011d97..484f84828 100644 --- a/libtransmission/tr-buffer.h +++ b/libtransmission/tr-buffer.h @@ -125,7 +125,7 @@ public: Buffer& operator=(Buffer&&) = default; template - Buffer(T const& data) + explicit Buffer(T const& data) { add(std::data(data), std::size(data)); } @@ -137,7 +137,7 @@ public: [[nodiscard]] auto empty() const noexcept { - return size() == 0U; + return evbuffer_get_length(buf_.get()) == 0; } [[nodiscard]] auto vecs(size_t n_bytes) const diff --git a/libtransmission/tr-utp.cc b/libtransmission/tr-utp.cc index 64b80ef87..d49dc7f8c 100644 --- a/libtransmission/tr-utp.cc +++ b/libtransmission/tr-utp.cc @@ -92,7 +92,7 @@ static void utp_on_accept(tr_session* const session, UTPSocket* const utp_sock) if (auto addrport = tr_address::fromSockaddr(reinterpret_cast(&from_storage)); addrport) { - auto const [addr, port] = *addrport; + auto const& [addr, port] = *addrport; session->addIncoming(addr, port, tr_peer_socket_utp_create(utp_sock)); } else