diff --git a/libtransmission/clients.cc b/libtransmission/clients.cc index 0daca8c4c..e54e4482b 100644 --- a/libtransmission/clients.cc +++ b/libtransmission/clients.cc @@ -211,8 +211,7 @@ bool decodeBitCometClient(char* buf, size_t buflen, std::string_view peer_id) // replaced exbc with FUTB. The encoding for BitComet Peer IDs changed // to Azureus-style as of BitComet version 0.59. auto mod = std::string_view{}; - auto const lead = std::string_view{ std::data(peer_id), std::min(std::size(peer_id), size_t{ 4 }) }; - if (lead == "exbc") + if (auto const lead = std::string_view{ std::data(peer_id), std::min(std::size(peer_id), size_t{ 4 }) }; lead == "exbc") { mod = ""sv; } diff --git a/libtransmission/handshake.cc b/libtransmission/handshake.cc index 6b3b7134a..fb597a106 100644 --- a/libtransmission/handshake.cc +++ b/libtransmission/handshake.cc @@ -497,9 +497,7 @@ static ReadState readVC(tr_handshake* handshake, tr_peerIo* peer_io) static ReadState readCryptoSelect(tr_handshake* handshake, tr_peerIo* peer_io) { - static size_t const needlen = sizeof(uint32_t) + sizeof(uint16_t); - - if (peer_io->readBufferSize() < needlen) + if (static size_t constexpr NeedLen = sizeof(uint32_t) + sizeof(uint16_t); peer_io->readBufferSize() < NeedLen) { return READ_LATER; } diff --git a/libtransmission/magnet-metainfo.cc b/libtransmission/magnet-metainfo.cc index 0a025cb96..9bb871758 100644 --- a/libtransmission/magnet-metainfo.cc +++ b/libtransmission/magnet-metainfo.cc @@ -202,8 +202,8 @@ void tr_magnet_metainfo::addWebseed(std::string_view webseed) } auto& urls = webseed_urls_; - auto const it = std::find(std::begin(urls), std::end(urls), webseed); - if (it != std::end(urls)) + + if (auto const it = std::find(std::begin(urls), std::end(urls), webseed); it != std::end(urls)) { return; } diff --git a/libtransmission/peer-msgs.cc b/libtransmission/peer-msgs.cc index 628a30257..ec1543c7a 100644 --- a/libtransmission/peer-msgs.cc +++ b/libtransmission/peer-msgs.cc @@ -924,8 +924,8 @@ static void sendLtepHandshake(tr_peerMsgsImpl* msgs) // It also adds "metadata_size" to the handshake message (not the // "m" dictionary) specifying an integer value of the number of // bytes of the metadata. - auto const info_dict_size = msgs->torrent->infoDictSize(); - if (allow_metadata_xfer && msgs->torrent->hasMetainfo() && info_dict_size > 0) + if (auto const info_dict_size = msgs->torrent->infoDictSize(); + allow_metadata_xfer && msgs->torrent->hasMetainfo() && info_dict_size > 0) { tr_variantDictAddInt(&val, TR_KEY_metadata_size, info_dict_size); } @@ -1979,8 +1979,7 @@ static size_t fillOutputBuffer(tr_peerMsgsImpl* msgs, time_t now) *** Metadata Pieces **/ - auto piece = int{}; - if (msgs->io->getWriteBufferSpace(now) >= METADATA_PIECE_SIZE && popNextMetadataRequest(msgs, &piece)) + if (auto piece = int{}; msgs->io->getWriteBufferSpace(now) >= METADATA_PIECE_SIZE && popNextMetadataRequest(msgs, &piece)) { auto ok = bool{ false }; diff --git a/libtransmission/platform.cc b/libtransmission/platform.cc index 9e6d8d10c..dc7b017d9 100644 --- a/libtransmission/platform.cc +++ b/libtransmission/platform.cc @@ -152,8 +152,8 @@ size_t tr_getDefaultConfigDirToBuf(char const* appname, char* buf, size_t buflen static std::string getXdgEntryFromUserDirs(std::string_view key) { auto content = std::vector{}; - auto const filename = fmt::format("{:s}/{:s}"sv, xdgConfigHome(), "user-dirs.dirs"sv); - if (!tr_sys_path_exists(filename) || !tr_loadFile(filename, content) || std::empty(content)) + if (auto const filename = fmt::format("{:s}/{:s}"sv, xdgConfigHome(), "user-dirs.dirs"sv); + !tr_sys_path_exists(filename) || !tr_loadFile(filename, content) || std::empty(content)) { return {}; } diff --git a/libtransmission/quark.cc b/libtransmission/quark.cc index 9f3093bb8..de670f78f 100644 --- a/libtransmission/quark.cc +++ b/libtransmission/quark.cc @@ -443,8 +443,8 @@ std::optional tr_quark_lookup(std::string_view key) // is it in our static array? auto constexpr Sbegin = std::begin(MyStatic); auto constexpr Send = std::end(MyStatic); - auto const sit = std::lower_bound(Sbegin, Send, key); - if (sit != Send && *sit == key) + + if (auto const sit = std::lower_bound(Sbegin, Send, key); sit != Send && *sit == key) { return std::distance(Sbegin, sit); } @@ -452,8 +452,7 @@ std::optional tr_quark_lookup(std::string_view key) /* was it added during runtime? */ auto const rbegin = std::begin(my_runtime); auto const rend = std::end(my_runtime); - auto const rit = std::find(rbegin, rend, key); - if (rit != rend) + if (auto const rit = std::find(rbegin, rend, key); rit != rend) { return TR_N_KEYS + std::distance(rbegin, rit); } diff --git a/libtransmission/resume.cc b/libtransmission/resume.cc index 633b3ae6d..7a42e289e 100644 --- a/libtransmission/resume.cc +++ b/libtransmission/resume.cc @@ -162,9 +162,8 @@ static auto loadDND(tr_variant* dict, tr_torrent* tor) { auto ret = tr_resume::fields_t{}; tr_variant* list = nullptr; - auto const n = tor->fileCount(); - if (tr_variantDictFindList(dict, TR_KEY_dnd, &list) && tr_variantListSize(list) == n) + if (auto const n = tor->fileCount(); tr_variantDictFindList(dict, TR_KEY_dnd, &list) && tr_variantListSize(list) == n) { auto wanted = std::vector{}; auto unwanted = std::vector{}; diff --git a/libtransmission/rpc-server.cc b/libtransmission/rpc-server.cc index fc7109ccd..5f67846bb 100644 --- a/libtransmission/rpc-server.cc +++ b/libtransmission/rpc-server.cc @@ -449,8 +449,8 @@ static void handle_request(struct evhttp_request* req, void* arg) if (req->type == EVHTTP_REQ_OPTIONS) { - char const* headers = evhttp_find_header(req->input_headers, "Access-Control-Request-Headers"); - if (headers != nullptr) + if (char const* headers = evhttp_find_header(req->input_headers, "Access-Control-Request-Headers"); + headers != nullptr) { evhttp_add_header(req->output_headers, "Access-Control-Allow-Headers", headers); } diff --git a/libtransmission/rpcimpl.cc b/libtransmission/rpcimpl.cc index c9a0476a4..010788b21 100644 --- a/libtransmission/rpcimpl.cc +++ b/libtransmission/rpcimpl.cc @@ -1129,8 +1129,8 @@ static char const* addTrackerUrls(tr_torrent* tor, tr_variant* urls) for (size_t i = 0, n = tr_variantListSize(urls); i < n; ++i) { auto announce = std::string_view(); - auto const* const val = tr_variantListChild(urls, i); - if (val == nullptr || !tr_variantGetStrView(val, &announce)) + + if (auto const* const val = tr_variantListChild(urls, i); val == nullptr || !tr_variantGetStrView(val, &announce)) { continue; } @@ -1181,8 +1181,8 @@ static char const* removeTrackers(tr_torrent* tor, tr_variant* ids) for (size_t i = 0, n = tr_variantListSize(ids); i < n; ++i) { auto id = int64_t{}; - auto const* const val = tr_variantListChild(ids, i); - if (val == nullptr || !tr_variantGetInt(val, &id)) + + if (auto const* const val = tr_variantListChild(ids, i); val == nullptr || !tr_variantGetInt(val, &id)) { continue; } diff --git a/libtransmission/torrent-magnet.cc b/libtransmission/torrent-magnet.cc index fc69e4adc..842361731 100644 --- a/libtransmission/torrent-magnet.cc +++ b/libtransmission/torrent-magnet.cc @@ -134,8 +134,7 @@ std::optional> tr_torrentGetMetadataPiece(tr_torrent cons auto const info_dict_size = tor->infoDictSize(); TR_ASSERT(info_dict_size > 0); auto const offset_in_info_dict = static_cast(piece) * METADATA_PIECE_SIZE; - auto const offset_in_file = tor->infoDictOffset() + offset_in_info_dict; - if (!in.seekg(offset_in_file)) + if (auto const offset_in_file = tor->infoDictOffset() + offset_in_info_dict; !in.seekg(offset_in_file)) { return {}; } diff --git a/libtransmission/tr-lpd.cc b/libtransmission/tr-lpd.cc index f712a1e3c..5eec2f61d 100644 --- a/libtransmission/tr-lpd.cc +++ b/libtransmission/tr-lpd.cc @@ -426,8 +426,7 @@ private: // If it doesn't look like a BEP14 message, discard it auto const msg = std::string_view{ std::data(foreign_msg), static_cast(res) }; - static auto constexpr SearchKey = "BT-SEARCH * HTTP/"sv; - if (msg.find(SearchKey) == std::string_view::npos) + if (static auto constexpr SearchKey = "BT-SEARCH * HTTP/"sv; msg.find(SearchKey) == std::string_view::npos) { return; } diff --git a/libtransmission/utils.cc b/libtransmission/utils.cc index 7a8ade7ee..b80692fb2 100644 --- a/libtransmission/utils.cc +++ b/libtransmission/utils.cc @@ -152,8 +152,7 @@ bool tr_saveFile(std::string_view filename, std::string_view contents, tr_error* } // If we saved it to disk successfully, move it from '.tmp' to the correct filename - auto const szfilename = tr_pathbuf{ filename }; - if (!tr_sys_file_close(fd, error) || !ok || !tr_sys_path_rename(tmp, szfilename, error)) + if (!tr_sys_file_close(fd, error) || !ok || !tr_sys_path_rename(tmp, tr_pathbuf{ filename }, error)) { return false; } diff --git a/libtransmission/variant.cc b/libtransmission/variant.cc index 380b1e650..7fc6829f9 100644 --- a/libtransmission/variant.cc +++ b/libtransmission/variant.cc @@ -393,9 +393,7 @@ static tr_variant* containerReserve(tr_variant* v, size_t count) { TR_ASSERT(tr_variantIsContainer(v)); - size_t const needed = v->val.l.count + count; - - if (needed > v->val.l.alloc) + if (size_t const needed = v->val.l.count + count; needed > v->val.l.alloc) { /* scale the alloc size in powers-of-2 */ size_t n = v->val.l.alloc != 0 ? v->val.l.alloc : 8; diff --git a/libtransmission/verify.cc b/libtransmission/verify.cc index 46f9d9cd2..62c5a4fd6 100644 --- a/libtransmission/verify.cc +++ b/libtransmission/verify.cc @@ -119,9 +119,7 @@ bool tr_verify_worker::verifyTorrent(tr_torrent* tor, std::atomic const& s /* if we're finishing a piece... */ if (left_in_piece == 0) { - auto const has_piece = sha->finish() == tor->pieceHash(piece); - - if (has_piece || had_piece) + if (auto const has_piece = sha->finish() == tor->pieceHash(piece); has_piece || had_piece) { tor->setHasPiece(piece, has_piece); changed |= has_piece != had_piece; diff --git a/qt/DBusInteropHelper.cc b/qt/DBusInteropHelper.cc index 9c864563f..bac8856da 100644 --- a/qt/DBusInteropHelper.cc +++ b/qt/DBusInteropHelper.cc @@ -39,14 +39,13 @@ void DBusInteropHelper::registerObject(QObject* parent) return; } - auto const service_name = QStringLiteral("com.transmissionbt.Transmission"); - if (!bus.registerService(service_name)) + if (auto const service_name = QStringLiteral("com.transmissionbt.Transmission"); !bus.registerService(service_name)) { qWarning() << "couldn't register" << qPrintable(service_name); } - auto const object_path = QStringLiteral("/com/transmissionbt/Transmission"); - if (!bus.registerObject(object_path, new InteropObject(parent), QDBusConnection::ExportAllSlots)) + if (auto const object_path = QStringLiteral("/com/transmissionbt/Transmission"); + !bus.registerObject(object_path, new InteropObject(parent), QDBusConnection::ExportAllSlots)) { qWarning() << "couldn't register" << qPrintable(object_path); } diff --git a/qt/FilterBar.cc b/qt/FilterBar.cc index a09f3ef2f..e364c305a 100644 --- a/qt/FilterBar.cc +++ b/qt/FilterBar.cc @@ -286,8 +286,8 @@ void FilterBar::refreshPref(int key) case Prefs::FILTER_TRACKERS: { auto const display_name = prefs_.getString(key); - auto rows = tracker_model_->findItems(display_name); - if (!rows.isEmpty()) + + if (auto rows = tracker_model_->findItems(display_name); !rows.isEmpty()) { tracker_combo_->setCurrentIndex(rows.front()->row()); } diff --git a/utils/remote.cc b/utils/remote.cc index 848917c83..bcaa08d0d 100644 --- a/utils/remote.cc +++ b/utils/remote.cc @@ -2317,8 +2317,7 @@ static int flush(char const* rpcurl, tr_variant* benc, Config& config) fmt::print(stderr, "posting:\n--------\n{:s}\n--------\n", json); } - auto const res = curl_easy_perform(curl); - if (res != CURLE_OK) + if (auto const res = curl_easy_perform(curl); res != CURLE_OK) { tr_logAddWarn(fmt::format(" ({}) {}", rpcurl_http, curl_easy_strerror(res))); status |= EXIT_FAILURE; diff --git a/utils/show.cc b/utils/show.cc index 2505b3ad4..af9ad9500 100644 --- a/utils/show.cc +++ b/utils/show.cc @@ -365,8 +365,8 @@ void doScrape(tr_torrent_metainfo const& metainfo) // print it out tr_variant top; auto* const begin = (char const*)evbuffer_pullup(buf, -1); - auto sv = std::string_view{ begin, evbuffer_get_length(buf) }; - if (!tr_variantFromBuf(&top, TR_VARIANT_PARSE_BENC | TR_VARIANT_PARSE_INPLACE, sv)) + if (auto sv = std::string_view{ begin, evbuffer_get_length(buf) }; + !tr_variantFromBuf(&top, TR_VARIANT_PARSE_BENC | TR_VARIANT_PARSE_INPLACE, sv)) { fmt::print("error parsing scrape response\n"); continue;