From 3036a76bebad6237a494a840d86a8afb122e80e9 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 17 Jan 2022 12:39:50 -0600 Subject: [PATCH] fix: sonarcloud code smells (#2421) --- gtk/Application.cc | 2 +- gtk/DetailsDialog.cc | 10 +++--- gtk/FileList.cc | 2 +- gtk/IconCache.cc | 4 +-- gtk/Notify.cc | 4 +-- gtk/Session.cc | 4 +-- gtk/Utils.cc | 2 +- libtransmission/announce-list.cc | 4 +-- libtransmission/announcer-http.cc | 2 +- libtransmission/announcer.cc | 4 +-- libtransmission/cache.cc | 18 +++++------ libtransmission/crypto-utils-ccrypto.cc | 4 +-- libtransmission/crypto-utils-cyassl.cc | 4 +-- libtransmission/crypto-utils-openssl.cc | 4 +-- libtransmission/crypto-utils-polarssl.cc | 4 +-- libtransmission/crypto.cc | 10 +++--- libtransmission/handshake.cc | 3 +- libtransmission/natpmp.cc | 8 ++--- libtransmission/net.cc | 8 ++--- libtransmission/peer-mgr.cc | 38 +++++++++++----------- libtransmission/peer-msgs.cc | 38 +++++++++++----------- libtransmission/platform.cc | 22 ++++++------- libtransmission/port-forwarding.cc | 2 +- libtransmission/ptrarray.cc | 4 +-- libtransmission/rpc-server.cc | 37 ++++++++++----------- libtransmission/rpcimpl.cc | 6 ++-- libtransmission/session-id.cc | 16 ++++----- libtransmission/session.cc | 6 ++-- libtransmission/stats.cc | 2 +- libtransmission/torrent-magnet.cc | 20 +++++++----- libtransmission/torrent-magnet.h | 2 +- libtransmission/torrent.cc | 7 ++-- libtransmission/tr-utp.cc | 17 +++++----- libtransmission/upnp.cc | 2 +- libtransmission/utils.cc | 4 +-- libtransmission/variant-json.cc | 10 +++--- libtransmission/watchdir-generic.cc | 4 +-- libtransmission/watchdir-inotify.cc | 4 +-- qt/DetailsDialog.cc | 2 +- utils/remote.cc | 41 ++++++++++-------------- utils/show.cc | 2 +- 41 files changed, 190 insertions(+), 197 deletions(-) diff --git a/gtk/Application.cc b/gtk/Application.cc index d8dd070f9..c6db8276a 100644 --- a/gtk/Application.cc +++ b/gtk/Application.cc @@ -246,7 +246,7 @@ void Application::Impl::show_details_dialog_for_selected_torrents() auto dialog = DetailsDialog::create(*wind_, core_); dialog->set_torrents(ids); dialog->signal_hide().connect([this, key]() { details_.erase(key); }); - dialog_it = details_.emplace(key, std::move(dialog)).first; + dialog_it = details_.try_emplace(key, std::move(dialog)).first; dialog_it->second->show(); } diff --git a/gtk/DetailsDialog.cc b/gtk/DetailsDialog.cc index 7f88f8d66..2169ebc43 100644 --- a/gtk/DetailsDialog.cc +++ b/gtk/DetailsDialog.cc @@ -1362,7 +1362,7 @@ void DetailsDialog::Impl::refreshPeerList(std::vector const& torren { auto const iter = store->append(); initPeerRow(iter, key, tr_torrentName(tor), s); - hash.emplace(key, Gtk::TreeRowReference(store, store->get_path(iter))); + hash.try_emplace(key, Gtk::TreeRowReference(store, store->get_path(iter))); } } } @@ -1432,7 +1432,7 @@ void DetailsDialog::Impl::refreshWebseedList(std::vector const& tor auto const iter = store->append(); (*iter)[webseed_cols.url] = url; (*iter)[webseed_cols.key] = key; - hash.emplace(key, Gtk::TreeRowReference(store, store->get_path(iter))); + hash.try_emplace(key, Gtk::TreeRowReference(store, store->get_path(iter))); } } } @@ -2133,7 +2133,7 @@ void DetailsDialog::Impl::refreshTracker(std::vector const& torrent (*iter)[tracker_cols.key] = gstr.str(); auto const p = store->get_path(iter); - hash.emplace(gstr.str(), Gtk::TreeRowReference(store, p)); + hash.try_emplace(gstr.str(), Gtk::TreeRowReference(store, p)); gtr_get_favicon_from_url( session, tracker.announce, @@ -2204,7 +2204,7 @@ void DetailsDialog::Impl::on_edit_trackers_response(int response, std::shared_pt if (response == Gtk::RESPONSE_ACCEPT) { - int const torrent_id = GPOINTER_TO_INT(dialog->get_data(TORRENT_ID_KEY)); + auto const torrent_id = GPOINTER_TO_INT(dialog->get_data(TORRENT_ID_KEY)); auto* const text_buffer = static_cast(dialog->get_data(TEXT_BUFFER_KEY)); tr_torrent* const tor = core_->find_torrent(torrent_id); @@ -2359,7 +2359,7 @@ void DetailsDialog::Impl::on_add_tracker_response(int response, std::shared_ptr< if (response == Gtk::RESPONSE_ACCEPT) { auto* e = static_cast(dialog->get_data(URL_ENTRY_KEY)); - int const torrent_id = GPOINTER_TO_INT(dialog->get_data(TORRENT_ID_KEY)); + auto const torrent_id = GPOINTER_TO_INT(dialog->get_data(TORRENT_ID_KEY)); auto const url = gtr_str_strip(e->get_text()); if (!url.empty()) diff --git a/gtk/FileList.cc b/gtk/FileList.cc index 9a5e7b530..41d9fe622 100644 --- a/gtk/FileList.cc +++ b/gtk/FileList.cc @@ -592,7 +592,7 @@ std::string buildFilename(tr_torrent const* tor, Gtk::TreeModel::iterator const& tokens.push_front(child->get_value(file_cols.label)); } - tokens.push_front(tr_torrentGetCurrentDir(tor)); + tokens.emplace_front(tr_torrentGetCurrentDir(tor)); return Glib::build_filename(tokens); } diff --git a/gtk/IconCache.cc b/gtk/IconCache.cc index e868bd458..4d6c8c3cc 100644 --- a/gtk/IconCache.cc +++ b/gtk/IconCache.cc @@ -54,7 +54,7 @@ std::unique_ptr icon_cache_new(Gtk::Widget& for_widget, Gtk::IconSize auto icons = std::make_unique(); icons->icon_theme = Gtk::IconTheme::get_for_screen(for_widget.get_screen()); icons->icon_size = get_size_in_pixels(icon_size); - icons->cache.emplace(VoidPixbufKey, create_void_pixbuf(icons->icon_size, icons->icon_size)); + icons->cache.try_emplace(VoidPixbufKey, create_void_pixbuf(icons->icon_size, icons->icon_size)); return icons; } @@ -152,7 +152,7 @@ Glib::RefPtr icon_cache_get_mime_type_icon(IconCache& icons, Glib:: if (pixbuf != nullptr) { - icons.cache.emplace(key, pixbuf); + icons.cache.try_emplace(key, pixbuf); } return pixbuf; diff --git a/gtk/Notify.cc b/gtk/Notify.cc index 605d32e93..18fbd3ee8 100644 --- a/gtk/Notify.cc +++ b/gtk/Notify.cc @@ -160,7 +160,7 @@ void notify_callback(Glib::RefPtr& res, TrNotification const& auto const id = Glib::VariantBase::cast_dynamic(result.get_child(0)).get(); - active_notifications.emplace(id, n); + active_notifications.try_emplace(id, n); } } // namespace @@ -207,7 +207,7 @@ void gtr_notify_torrent_completed(Glib::RefPtr const& core, int torrent } std::map hints; - hints.emplace("category", StringVariantType::create("transfer.complete")); + hints.try_emplace("category", StringVariantType::create("transfer.complete")); proxy->call( "Notify", diff --git a/gtk/Session.cc b/gtk/Session.cc index fd63a9e09..6d47811b1 100644 --- a/gtk/Session.cc +++ b/gtk/Session.cc @@ -1340,8 +1340,8 @@ namespace int gtr_compare_double(double const a, double const b, int decimal_places) { int ret; - int64_t const ia = (int64_t)(a * pow(10, decimal_places)); - int64_t const ib = (int64_t)(b * pow(10, decimal_places)); + auto const ia = int64_t(a * pow(10, decimal_places)); + auto const ib = int64_t(b * pow(10, decimal_places)); if (ia < ib) { diff --git a/gtk/Utils.cc b/gtk/Utils.cc index f7857525d..1263e301b 100644 --- a/gtk/Utils.cc +++ b/gtk/Utils.cc @@ -98,7 +98,7 @@ Glib::ustring tr_strltime(time_t seconds) seconds = 0; } - int const days = (int)(seconds / 86400); + auto const days = (int)(seconds / 86400); int const hours = (seconds % 86400) / 3600; int const minutes = (seconds % 3600) / 60; seconds = (seconds % 3600) % 60; diff --git a/libtransmission/announce-list.cc b/libtransmission/announce-list.cc index d7f04e83b..6df49ee82 100644 --- a/libtransmission/announce-list.cc +++ b/libtransmission/announce-list.cc @@ -245,9 +245,7 @@ bool tr_announce_list::save(std::string const& torrent_file, tr_error** error) c // confirm that it's good by parsing it back again auto const contents = tr_variantToStr(&metainfo, TR_VARIANT_FMT_BENC); tr_variantFree(&metainfo); - - auto tm = tr_torrent_metainfo{}; - if (!tm.parseBenc(contents)) + if (auto tm = tr_torrent_metainfo{}; !tm.parseBenc(contents)) { return false; } diff --git a/libtransmission/announcer-http.cc b/libtransmission/announcer-http.cc index 246c0dd36..b05f93466 100644 --- a/libtransmission/announcer-http.cc +++ b/libtransmission/announcer-http.cc @@ -126,7 +126,7 @@ static tr_pex* listToPex(tr_variant* peerList, size_t* setme_len) { size_t n = 0; size_t const len = tr_variantListSize(peerList); - tr_pex* pex = tr_new0(tr_pex, len); + auto* const pex = tr_new0(tr_pex, len); for (size_t i = 0; i < len; ++i) { diff --git a/libtransmission/announcer.cc b/libtransmission/announcer.cc index 72e15f839..a740ca8a0 100644 --- a/libtransmission/announcer.cc +++ b/libtransmission/announcer.cc @@ -805,7 +805,7 @@ static tr_announce_request* announce_request_new( tr_tier const* tier, tr_announce_event event) { - tr_announce_request* req = tr_new0(tr_announce_request, 1); + auto* const req = tr_new0(tr_announce_request, 1); req->port = tr_sessionGetPublicPeerPort(announcer->session); req->announce_url = tier->currentTracker->announce_url; req->tracker_id_str = tr_strdup(tier->currentTracker->tracker_id_str); @@ -1151,7 +1151,7 @@ static void tierAnnounce(tr_announcer* announcer, tr_tier* tier) tr_announce_event announce_event = tier_announce_event_pull(tier); tr_announce_request* req = announce_request_new(announcer, tor, tier, announce_event); - struct announce_data* data = tr_new0(struct announce_data, 1); + auto* const data = tr_new0(struct announce_data, 1); data->session = announcer->session; data->tierId = tier->key; data->isRunningOnSuccess = tor->isRunning; diff --git a/libtransmission/cache.cc b/libtransmission/cache.cc index 1bfbc7e02..8a149e674 100644 --- a/libtransmission/cache.cc +++ b/libtransmission/cache.cc @@ -22,9 +22,9 @@ #include "trevent.h" #include "utils.h" -#define MY_NAME "Cache" +static char constexpr MyName[] = "Cache"; -#define dbgmsg(...) tr_logAddDeepNamed(MY_NAME, __VA_ARGS__) +#define dbgmsg(...) tr_logAddDeepNamed(MyName, __VA_ARGS__) /**** ***** @@ -74,7 +74,7 @@ struct run_info static int getBlockRun(tr_cache const* cache, int pos, struct run_info* info) { int const n = tr_ptrArraySize(&cache->blocks); - struct cache_block const* const* blocks = (struct cache_block const* const*)tr_ptrArrayBase(&cache->blocks); + auto const* const* blocks = (struct cache_block const* const*)tr_ptrArrayBase(&cache->blocks); struct cache_block const* ref = blocks[pos]; tr_block_index_t block = ref->block; int len = 0; @@ -162,9 +162,9 @@ static int calcRuns(tr_cache const* cache, struct run_info* runs) static int flushContiguous(tr_cache* cache, int pos, int n) { int err = 0; - uint8_t* buf = tr_new(uint8_t, n * MAX_BLOCK_SIZE); - uint8_t* walk = buf; - struct cache_block** blocks = (struct cache_block**)tr_ptrArrayBase(&cache->blocks); + auto* const buf = tr_new(uint8_t, n * MAX_BLOCK_SIZE); + auto* walk = buf; + auto** blocks = (struct cache_block**)tr_ptrArrayBase(&cache->blocks); struct cache_block* b = blocks[pos]; tr_torrent* tor = b->tor; @@ -219,7 +219,7 @@ static int cacheTrim(tr_cache* cache) /* Amount of cache that should be removed by the flush. This influences how large * runs can grow as well as how often flushes will happen. */ int const cacheCutoff = 1 + cache->max_blocks / 4; - struct run_info* runs = tr_new(struct run_info, tr_ptrArraySize(&cache->blocks)); + auto* const runs = tr_new(struct run_info, tr_ptrArraySize(&cache->blocks)); int i = 0; int j = 0; @@ -252,7 +252,7 @@ int tr_cacheSetLimit(tr_cache* cache, int64_t max_bytes) cache->max_blocks = getMaxBlocks(max_bytes); tr_logAddNamedDbg( - MY_NAME, + MyName, "Maximum cache size set to %s (%d blocks)", tr_formatter_mem_B(cache->max_bytes).c_str(), cache->max_blocks); @@ -267,7 +267,7 @@ int64_t tr_cacheGetLimit(tr_cache const* cache) tr_cache* tr_cacheNew(int64_t max_bytes) { - tr_cache* cache = tr_new0(tr_cache, 1); + auto* const cache = tr_new0(tr_cache, 1); cache->blocks = {}; cache->max_bytes = max_bytes; cache->max_blocks = getMaxBlocks(max_bytes); diff --git a/libtransmission/crypto-utils-ccrypto.cc b/libtransmission/crypto-utils-ccrypto.cc index e0fe64646..2ae132f59 100644 --- a/libtransmission/crypto-utils-ccrypto.cc +++ b/libtransmission/crypto-utils-ccrypto.cc @@ -55,7 +55,7 @@ extern "C" namespace { -#define MY_NAME "tr_crypto_utils" +static char constexpr MyName[] = "tr_crypto_utils"; char const* ccrypto_error_to_str(CCCryptorStatus error_code) { @@ -100,7 +100,7 @@ void log_ccrypto_error(CCCryptorStatus error_code, char const* file, int line) file, line, TR_LOG_ERROR, - MY_NAME, + MyName, "CCrypto error (%d): %s", error_code, ccrypto_error_to_str(error_code)); diff --git a/libtransmission/crypto-utils-cyassl.cc b/libtransmission/crypto-utils-cyassl.cc index 14049ce80..107b39226 100644 --- a/libtransmission/crypto-utils-cyassl.cc +++ b/libtransmission/crypto-utils-cyassl.cc @@ -50,7 +50,7 @@ struct tr_dh_ctx **** ***/ -#define MY_NAME "tr_crypto_utils" +static char constexpr MyName[] = "tr_crypto_utils"; static void log_cyassl_error(int error_code, char const* file, int line) { @@ -65,7 +65,7 @@ static void log_cyassl_error(int error_code, char const* file, int line) CTaoCryptErrorString(error_code, error_message); #endif - tr_logAddMessage(file, line, TR_LOG_ERROR, MY_NAME, "CyaSSL error: %s", error_message); + tr_logAddMessage(file, line, TR_LOG_ERROR, MyName, "CyaSSL error: %s", error_message); } } diff --git a/libtransmission/crypto-utils-openssl.cc b/libtransmission/crypto-utils-openssl.cc index 58b455578..aef76636f 100644 --- a/libtransmission/crypto-utils-openssl.cc +++ b/libtransmission/crypto-utils-openssl.cc @@ -34,7 +34,7 @@ **** ***/ -#define MY_NAME "tr_crypto_utils" +static char constexpr MyName[] = "tr_crypto_utils"; static void log_openssl_error(char const* file, int line) { @@ -62,7 +62,7 @@ static void log_openssl_error(char const* file, int line) #endif ERR_error_string_n(error_code, buf, sizeof(buf)); - tr_logAddMessage(file, line, TR_LOG_ERROR, MY_NAME, "OpenSSL error: %s", buf); + tr_logAddMessage(file, line, TR_LOG_ERROR, MyName, "OpenSSL error: %s", buf); } } diff --git a/libtransmission/crypto-utils-polarssl.cc b/libtransmission/crypto-utils-polarssl.cc index 202a545d0..858e5eb86 100644 --- a/libtransmission/crypto-utils-polarssl.cc +++ b/libtransmission/crypto-utils-polarssl.cc @@ -40,7 +40,7 @@ **** ***/ -#define MY_NAME "tr_crypto_utils" +static char constexpr MyName[] = "tr_crypto_utils"; using api_ctr_drbg_context = API(ctr_drbg_context); using api_sha1_context = API(sha1_context); @@ -60,7 +60,7 @@ static void log_polarssl_error(int error_code, char const* file, int line) error_strerror(error_code, error_message, sizeof(error_message)); #endif - tr_logAddMessage(file, line, TR_LOG_ERROR, MY_NAME, "PolarSSL error: %s", error_message); + tr_logAddMessage(file, line, TR_LOG_ERROR, MyName, "PolarSSL error: %s", error_message); } } diff --git a/libtransmission/crypto.cc b/libtransmission/crypto.cc index 61d50a752..a5aaf8352 100644 --- a/libtransmission/crypto.cc +++ b/libtransmission/crypto.cc @@ -20,10 +20,10 @@ *** **/ -#define PRIME_LEN 96 -#define DH_PRIVKEY_LEN 20 +static auto constexpr PrimeLen = size_t{ 96 }; +static auto constexpr DhPrivkeyLen = size_t{ 20 }; -static uint8_t const dh_P[PRIME_LEN] = { +static uint8_t constexpr dh_P[PrimeLen] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, // 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, // 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6, // @@ -34,7 +34,7 @@ static uint8_t const dh_P[PRIME_LEN] = { 0xA6, 0x3A, 0x36, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x05, 0x63, // }; -static uint8_t const dh_G[] = { 2 }; +static uint8_t constexpr dh_G[] = { 2 }; /** *** @@ -46,7 +46,7 @@ static void ensureKeyExists(tr_crypto* crypto) { size_t public_key_length = 0; crypto->dh = tr_dh_new(dh_P, sizeof(dh_P), dh_G, sizeof(dh_G)); - tr_dh_make_key(crypto->dh, DH_PRIVKEY_LEN, crypto->myPublicKey, &public_key_length); + tr_dh_make_key(crypto->dh, DhPrivkeyLen, crypto->myPublicKey, &public_key_length); TR_ASSERT(public_key_length == KEY_LEN); } diff --git a/libtransmission/handshake.cc b/libtransmission/handshake.cc index 2678a2178..43b78938c 100644 --- a/libtransmission/handshake.cc +++ b/libtransmission/handshake.cc @@ -245,8 +245,7 @@ static handshake_parse_err_t parseHandshake(tr_handshake* handshake, struct evbu /* torrent hash */ auto hash = tr_sha1_digest_t{}; tr_peerIoReadBytes(handshake->io, inbuf, std::data(hash), std::size(hash)); - auto const torrent_hash = tr_peerIoGetTorrentHash(handshake->io); - if (!torrent_hash || *torrent_hash != hash) + if (auto const torrent_hash = tr_peerIoGetTorrentHash(handshake->io); !torrent_hash || *torrent_hash != hash) { dbgmsg(handshake, "peer returned the wrong hash. wtf?"); return HANDSHAKE_BAD_TORRENT; diff --git a/libtransmission/natpmp.cc b/libtransmission/natpmp.cc index aaa8c55ef..05099be53 100644 --- a/libtransmission/natpmp.cc +++ b/libtransmission/natpmp.cc @@ -22,8 +22,8 @@ #include "port-forwarding.h" #include "utils.h" -#define LIFETIME_SECS 3600 -#define COMMAND_WAIT_SECS 8 +static auto constexpr LifetimeSecs = uint32_t{ 3600 }; +static auto constexpr CommandWaitSecs = time_t{ 8 }; static char const* getKey(void) { @@ -110,7 +110,7 @@ static bool canSendCommand(struct tr_natpmp const* nat) static void setCommandTime(struct tr_natpmp* nat) { - nat->command_time = tr_time() + COMMAND_WAIT_SECS; + nat->command_time = tr_time() + CommandWaitSecs; } tr_port_forwarding tr_natpmpPulse(struct tr_natpmp* nat, tr_port private_port, bool is_enabled, tr_port* public_port) @@ -199,7 +199,7 @@ tr_port_forwarding tr_natpmpPulse(struct tr_natpmp* nat, tr_port private_port, b if (nat->state == TR_NATPMP_SEND_MAP && canSendCommand(nat)) { - int const val = sendnewportmappingrequest(&nat->natpmp, NATPMP_PROTOCOL_TCP, private_port, private_port, LIFETIME_SECS); + int const val = sendnewportmappingrequest(&nat->natpmp, NATPMP_PROTOCOL_TCP, private_port, private_port, LifetimeSecs); logVal("sendnewportmappingrequest", val); nat->state = val < 0 ? TR_NATPMP_ERR : TR_NATPMP_RECV_MAP; setCommandTime(nat); diff --git a/libtransmission/net.cc b/libtransmission/net.cc index d062b657c..5608ae913 100644 --- a/libtransmission/net.cc +++ b/libtransmission/net.cc @@ -220,7 +220,7 @@ bool tr_address_from_sockaddr_storage(tr_address* setme_addr, tr_port* setme_por { if (from->ss_family == AF_INET) { - struct sockaddr_in const* sin = (struct sockaddr_in const*)from; + auto const* const sin = (struct sockaddr_in const*)from; setme_addr->type = TR_AF_INET; setme_addr->addr.addr4.s_addr = sin->sin_addr.s_addr; *setme_port = sin->sin_port; @@ -229,7 +229,7 @@ bool tr_address_from_sockaddr_storage(tr_address* setme_addr, tr_port* setme_por if (from->ss_family == AF_INET6) { - struct sockaddr_in6 const* sin6 = (struct sockaddr_in6 const*)from; + auto const* const sin6 = (struct sockaddr_in6 const*)from; setme_addr->type = TR_AF_INET6; setme_addr->addr.addr6 = sin6->sin6_addr; *setme_port = sin6->sin6_port; @@ -702,13 +702,13 @@ static bool isMartianAddr(struct tr_address const* a) { case TR_AF_INET: { - unsigned char const* address = (unsigned char const*)&a->addr.addr4; + auto const* const address = (unsigned char const*)&a->addr.addr4; return address[0] == 0 || address[0] == 127 || (address[0] & 0xE0) == 0xE0; } case TR_AF_INET6: { - unsigned char const* address = (unsigned char const*)&a->addr.addr6; + auto const* const address = (unsigned char const*)&a->addr.addr6; return address[0] == 0xFF || (memcmp(address, zeroes, 15) == 0 && (address[15] == 0 || address[15] == 1)); } diff --git a/libtransmission/peer-mgr.cc b/libtransmission/peer-mgr.cc index 8a3b68856..d3c8466fc 100644 --- a/libtransmission/peer-mgr.cc +++ b/libtransmission/peer-mgr.cc @@ -871,7 +871,7 @@ static void peerCallbackFunc(tr_peer* peer, tr_peer_event const* e, void* vs) break; default: - TR_ASSERT_MSG(false, "unhandled peer event type %d", (int)e->eventType); + TR_ASSERT_MSG(false, "unhandled peer event type %d", int(e->eventType)); } } @@ -1022,7 +1022,7 @@ static bool on_handshake_done(tr_handshake_result const& result) if (!result.readAnythingFromPeer) { - tordbg(s, "marking peer %s as unreachable... numFails is %d", tr_atomAddrStr(atom), (int)atom->numFails); + tordbg(s, "marking peer %s as unreachable... numFails is %d", tr_atomAddrStr(atom), int(atom->numFails)); atom->flags2 |= MyflagUnreachable; } } @@ -1145,7 +1145,7 @@ void tr_peerMgrSetSwarmIsAllSeeds(tr_torrent* tor) auto* const swarm = tor->swarm; auto atomCount = int{}; - struct peer_atom** atoms = (struct peer_atom**)tr_ptrArrayPeek(&swarm->pool, &atomCount); + auto** atoms = (struct peer_atom**)tr_ptrArrayPeek(&swarm->pool, &atomCount); for (int i = 0; i < atomCount; ++i) { atomSetSeed(swarm, atoms[i]); @@ -1253,7 +1253,7 @@ void tr_peerMgrGotBadPiece(tr_torrent* tor, tr_piece_index_t pieceIndex) "peer %s contributed to corrupt piece (%d); now has %d strikes", tr_atomAddrStr(peer->atom), pieceIndex, - (int)peer->strikes + 1); + int(peer->strikes + 1)); addStrike(s, peer); } } @@ -1365,7 +1365,7 @@ int tr_peerMgrGetPeers(tr_torrent const* tor, tr_pex** setme_pex, uint8_t af, ui } else /* TR_PEERS_INTERESTING */ { - struct peer_atom** atomBase = (struct peer_atom**)tr_ptrArrayBase(&s->pool); + auto** atomBase = (struct peer_atom**)tr_ptrArrayBase(&s->pool); int const n = tr_ptrArraySize(&s->pool); atoms = tr_new(struct peer_atom*, n); @@ -1385,7 +1385,7 @@ int tr_peerMgrGetPeers(tr_torrent const* tor, tr_pex** setme_pex, uint8_t af, ui **/ int const n = std::min(atomCount, maxCount); - tr_pex* const pex = tr_new0(tr_pex, n); + auto* const pex = tr_new0(tr_pex, n); tr_pex* walk = pex; auto count = int{}; @@ -1657,7 +1657,7 @@ uint64_t tr_peerMgrGetDesiredAvailable(tr_torrent const* tor) return 0; } - tr_peer const** const peers = (tr_peer const**)tr_ptrArrayBase(&s->peers); + auto const** const peers = (tr_peer const**)tr_ptrArrayBase(&s->peers); for (size_t i = 0; i < n_peers; ++i) { if (peers[i]->atom != nullptr && atomIsSeed(peers[i]->atom)) @@ -1806,9 +1806,9 @@ struct tr_peer_stat* tr_peerMgrPeerStats(tr_torrent const* tor, int* setmeCount) TR_ASSERT(tr_isTorrent(tor)); TR_ASSERT(tor->swarm->manager != nullptr); - tr_peerMsgs** peers = (tr_peerMsgs**)tr_ptrArrayBase(&tor->swarm->peers); + auto** peers = (tr_peerMsgs**)tr_ptrArrayBase(&tor->swarm->peers); int const size = tr_ptrArraySize(&tor->swarm->peers); - tr_peer_stat* ret = tr_new0(tr_peer_stat, size); + auto* const ret = tr_new0(tr_peer_stat, size); time_t const now = tr_time(); uint64_t const now_msec = tr_time_msec(); @@ -2145,8 +2145,8 @@ static void rechokeUploads(tr_swarm* s, uint64_t const now) auto const lock = s->manager->unique_lock(); int const peerCount = tr_ptrArraySize(&s->peers); - tr_peerMsgs** peers = (tr_peerMsgs**)tr_ptrArrayBase(&s->peers); - struct ChokeData* choke = tr_new0(struct ChokeData, peerCount); + auto** peers = (tr_peerMsgs**)tr_ptrArrayBase(&s->peers); + auto* const choke = tr_new0(struct ChokeData, peerCount); tr_session const* session = s->manager->session; bool const chokeAll = !s->tor->clientCanUpload(); bool const isMaxedOut = isBandwidthMaxedOut(s->tor->bandwidth, now, TR_UP); @@ -2312,7 +2312,7 @@ static bool shouldPeerBeClosed(tr_swarm const* s, tr_peer const* peer, int peerC /* disconnect if it's been too long since piece data has been transferred. * this is on a sliding scale based on number of available peers... */ { - int const relaxStrictnessIfFewerThanN = (int)(getMaxPeerCount(tor) * 0.9 + 0.5); + auto const relaxStrictnessIfFewerThanN = int(getMaxPeerCount(tor) * 0.9 + 0.5); /* if we have >= relaxIfFewerThan, strictness is 100%. * if we have zero connections, strictness is 0% */ float const strictness = peerCount >= relaxStrictnessIfFewerThanN ? 1.0 : @@ -2429,7 +2429,7 @@ static void closePeer(tr_peer* peer) else { ++atom->numFails; - tordbg(s, "incremented atom %s numFails to %d", tr_atomAddrStr(atom), (int)atom->numFails); + tordbg(s, "incremented atom %s numFails to %d", tr_atomAddrStr(atom), int(atom->numFails)); } tordbg(s, "removing bad peer %s", tr_atomAddrStr(peer->atom)); @@ -2583,7 +2583,7 @@ static void reconnectPulse(evutil_socket_t /*fd*/, short /*what*/, void* vmgr) enforceSessionPeerLimit(mgr->session); // try to make new peer connections - auto const max_connections_per_pulse = (int)(MaxConnectionsPerSecond * (ReconnectPeriodMsec / 1000.0)); + auto const max_connections_per_pulse = int(MaxConnectionsPerSecond * (ReconnectPeriodMsec / 1000.0)); makeNewPeerConnections(mgr, max_connections_per_pulse); } @@ -2743,14 +2743,14 @@ static void atomPulse(evutil_socket_t /*fd*/, short /*what*/, void* vmgr) tr_swarm* s = tor->swarm; int const maxAtomCount = getMaxAtomCount(tor); auto atomCount = int{}; - peer_atom** const atoms = (peer_atom**)tr_ptrArrayPeek(&s->pool, &atomCount); + auto** const atoms = (peer_atom**)tr_ptrArrayPeek(&s->pool, &atomCount); if (atomCount > maxAtomCount) /* we've got too many atoms... time to prune */ { int keepCount = 0; int testCount = 0; - struct peer_atom** keep = tr_new(struct peer_atom*, atomCount); - struct peer_atom** test = tr_new(struct peer_atom*, atomCount); + auto** keep = tr_new(struct peer_atom*, atomCount); + auto** test = tr_new(struct peer_atom*, atomCount); /* keep the ones that are in use */ for (int i = 0; i < atomCount; ++i) @@ -2930,7 +2930,7 @@ static uint64_t getPeerCandidateScore(tr_torrent const* tor, struct peer_atom co static bool calculateAllSeeds(tr_swarm* swarm) { int nAtoms = 0; - struct peer_atom** atoms = (struct peer_atom**)tr_ptrArrayPeek(&swarm->pool, &nAtoms); + auto** atoms = (struct peer_atom**)tr_ptrArrayPeek(&swarm->pool, &nAtoms); for (int i = 0; i < nAtoms; ++i) { @@ -3009,7 +3009,7 @@ static std::vector getPeerCandidates(tr_session* session, size_t } auto nAtoms = int{}; - peer_atom** atoms = (peer_atom**)tr_ptrArrayPeek(&tor->swarm->pool, &nAtoms); + auto** atoms = (peer_atom**)tr_ptrArrayPeek(&tor->swarm->pool, &nAtoms); for (int i = 0; i < nAtoms; ++i) { diff --git a/libtransmission/peer-msgs.cc b/libtransmission/peer-msgs.cc index 85e122528..bb5626b0f 100644 --- a/libtransmission/peer-msgs.cc +++ b/libtransmission/peer-msgs.cc @@ -547,7 +547,7 @@ private: void set_active(tr_direction direction, bool active) { - // TODO dbgmsg(msgs, "direction [%d] is_active [%d]", (int)direction, (int)is_active); + // TODO dbgmsg(msgs, "direction [%d] is_active [%d]", int(direction), int(is_active)); auto& val = is_active_[direction]; if (val != active) { @@ -1135,7 +1135,7 @@ static void parseLtepHandshake(tr_peerMsgsImpl* msgs, uint32_t len, struct evbuf /* arbitrary limit, should be more than enough */ if (len <= 4096) { - dbgmsg(msgs, "here is the handshake: [%*.*s]", TR_ARG_TUPLE((int)len, (int)len, tmp)); + dbgmsg(msgs, "here is the handshake: [%*.*s]", TR_ARG_TUPLE(int(len), int(len), tmp)); } else { @@ -1166,14 +1166,14 @@ static void parseLtepHandshake(tr_peerMsgsImpl* msgs, uint32_t len, struct evbuf { msgs->peerSupportsPex = i != 0; msgs->ut_pex_id = (uint8_t)i; - dbgmsg(msgs, "msgs->ut_pex is %d", (int)msgs->ut_pex_id); + dbgmsg(msgs, "msgs->ut_pex is %d", int(msgs->ut_pex_id)); } if (tr_variantDictFindInt(sub, TR_KEY_ut_metadata, &i)) { msgs->peerSupportsMetadataXfer = i != 0; msgs->ut_metadata_id = (uint8_t)i; - dbgmsg(msgs, "msgs->ut_metadata_id is %d", (int)msgs->ut_metadata_id); + dbgmsg(msgs, "msgs->ut_metadata_id is %d", int(msgs->ut_metadata_id)); } if (tr_variantDictFindInt(sub, TR_KEY_ut_holepunch, &i)) @@ -1201,7 +1201,7 @@ static void parseLtepHandshake(tr_peerMsgsImpl* msgs, uint32_t len, struct evbuf { pex.port = htons((uint16_t)i); msgs->publishClientGotPort(pex.port); - dbgmsg(msgs, "peer's port is now %d", (int)i); + dbgmsg(msgs, "peer's port is now %d", int(i)); } uint8_t const* addr = nullptr; @@ -1235,7 +1235,7 @@ static void parseUtMetadata(tr_peerMsgsImpl* msgs, uint32_t msglen, struct evbuf int64_t msg_type = -1; int64_t piece = -1; int64_t total_size = 0; - char* const tmp = tr_new(char, msglen); + auto* const tmp = tr_new(char, msglen); tr_peerIoReadBytes(msgs->io, inbuf, tmp, msglen); char const* const msg_end = (char const*)tmp + msglen; @@ -1250,7 +1250,7 @@ static void parseUtMetadata(tr_peerMsgsImpl* msgs, uint32_t msglen, struct evbuf tr_variantFree(&dict); } - dbgmsg(msgs, "got ut_metadata msg: type %d, piece %d, total_size %d", (int)msg_type, (int)piece, (int)total_size); + dbgmsg(msgs, "got ut_metadata msg: type %d, piece %d, total_size %d", int(msg_type), int(piece), int(total_size)); if (msg_type == METADATA_MSG_TYPE_REJECT) { @@ -1391,7 +1391,7 @@ static void parseLtep(tr_peerMsgsImpl* msgs, uint32_t msglen, struct evbuffer* i } else { - dbgmsg(msgs, "skipping unknown ltep message (%d)", (int)ltep_msgid); + dbgmsg(msgs, "skipping unknown ltep message (%d)", int(ltep_msgid)); evbuffer_drain(inbuf, msglen); } } @@ -1611,7 +1611,7 @@ static ReadState readBtPiece(tr_peerMsgsImpl* msgs, struct evbuffer* inbuf, size req->index, req->offset, req->length, - (int)(req->length - evbuffer_get_length(block_buffer))); + int(req->length - evbuffer_get_length(block_buffer))); if (evbuffer_get_length(block_buffer) < req->length) { @@ -1643,7 +1643,7 @@ static ReadState readBtMessage(tr_peerMsgsImpl* msgs, struct evbuffer* inbuf, si --msglen; /* id length */ - dbgmsg(msgs, "got BT id %d, len %d, buffer size is %zu", (int)id, (int)msglen, inlen); + dbgmsg(msgs, "got BT id %d, len %d, buffer size is %zu", int(id), int(msglen), inlen); if (inlen < msglen) { @@ -1652,7 +1652,7 @@ static ReadState readBtMessage(tr_peerMsgsImpl* msgs, struct evbuffer* inbuf, si if (!messageLengthIsCorrect(msgs, id, msglen + 1)) { - dbgmsg(msgs, "bad packet - BT message #%d with a length of %d", (int)id, (int)msglen); + dbgmsg(msgs, "bad packet - BT message #%d with a length of %d", int(id), int(msglen)); msgs->publishError(EMSGSIZE); return READ_ERR; } @@ -1712,7 +1712,7 @@ static ReadState readBtMessage(tr_peerMsgsImpl* msgs, struct evbuffer* inbuf, si case BtBitfield: { - uint8_t* tmp = tr_new(uint8_t, msglen); + auto* const tmp = tr_new(uint8_t, msglen); dbgmsg(msgs, "got a bitfield"); tr_peerIoReadBytes(msgs->io, inbuf, tmp, msglen); msgs->have.setRaw(tmp, msglen); @@ -1870,7 +1870,7 @@ static ReadState readBtMessage(tr_peerMsgsImpl* msgs, struct evbuffer* inbuf, si break; default: - dbgmsg(msgs, "peer sent us an UNKNOWN: %d", (int)id); + dbgmsg(msgs, "peer sent us an UNKNOWN: %d", int(id)); tr_peerIoDrain(msgs->io, inbuf, msglen); break; } @@ -1982,7 +1982,7 @@ static ReadState canRead(tr_peerIo* io, void* vmsgs, size_t* piece) default: #ifdef TR_ENABLE_ASSERTS - TR_ASSERT_MSG(false, "unhandled peer messages state %d", (int)msgs->state); + TR_ASSERT_MSG(false, "unhandled peer messages state %d", int(msgs->state)); #else ret = READ_ERR; break; @@ -1990,7 +1990,7 @@ static ReadState canRead(tr_peerIo* io, void* vmsgs, size_t* piece) } } - dbgmsg(msgs, "canRead: ret is %d", (int)ret); + dbgmsg(msgs, "canRead: ret is %d", int(ret)); return ret; } @@ -2366,8 +2366,8 @@ static void tellPeerWhatWeHave(tr_peerMsgsImpl* msgs) /* some peers give us error messages if we send more than this many peers in a single pex message http://wiki.theory.org/BitTorrentPeerExchangeConventions */ -#define MAX_PEX_ADDED 50 -#define MAX_PEX_DROPPED 50 +static auto constexpr MaxPexAdded = int{ 50 }; +static auto constexpr MaxPexDropped = int{ 50 }; struct PexDiffs { @@ -2384,7 +2384,7 @@ static void pexAddedCb(void const* vpex, void* userData) auto* diffs = static_cast(userData); auto const* pex = static_cast(vpex); - if (diffs->addedCount < MAX_PEX_ADDED) + if (diffs->addedCount < MaxPexAdded) { diffs->added[diffs->addedCount++] = *pex; diffs->elements[diffs->elementCount++] = *pex; @@ -2396,7 +2396,7 @@ static constexpr void pexDroppedCb(void const* vpex, void* userData) auto* diffs = static_cast(userData); auto const* pex = static_cast(vpex); - if (diffs->droppedCount < MAX_PEX_DROPPED) + if (diffs->droppedCount < MaxPexDropped) { diffs->dropped[diffs->droppedCount++] = *pex; } diff --git a/libtransmission/platform.cc b/libtransmission/platform.cc index b9d7fb72c..1d662ac0a 100644 --- a/libtransmission/platform.cc +++ b/libtransmission/platform.cc @@ -61,7 +61,7 @@ static char* tr_buildPath(char const* first_element, ...) element = va_arg(vl, char const*); } va_end(vl); - char* const buf = tr_new(char, bufLen); + auto* const buf = tr_new(char, bufLen); if (buf == nullptr) { return nullptr; @@ -256,19 +256,19 @@ static char const* getHomeDir(void) return home; } -#if defined(__APPLE__) || defined(_WIN32) -#define RESUME_SUBDIR "Resume" -#define TORRENT_SUBDIR "Torrents" -#else -#define RESUME_SUBDIR "resume" -#define TORRENT_SUBDIR "torrents" -#endif - void tr_setConfigDir(tr_session* session, std::string_view config_dir) { +#if defined(__APPLE__) || defined(_WIN32) + auto constexpr ResumeSubdir = "Resume"sv; + auto constexpr TorrentSubdir = "Torrents"sv; +#else + auto constexpr ResumeSubdir = "resume"sv; + auto constexpr TorrentSubdir = "torrents"sv; +#endif + session->config_dir = config_dir; - session->resume_dir = tr_strvPath(config_dir, RESUME_SUBDIR); - session->torrent_dir = tr_strvPath(config_dir, TORRENT_SUBDIR); + session->resume_dir = tr_strvPath(config_dir, ResumeSubdir); + session->torrent_dir = tr_strvPath(config_dir, TorrentSubdir); tr_sys_dir_create(session->resume_dir.c_str(), TR_SYS_DIR_CREATE_PARENTS, 0777, nullptr); tr_sys_dir_create(session->torrent_dir.c_str(), TR_SYS_DIR_CREATE_PARENTS, 0777, nullptr); } diff --git a/libtransmission/port-forwarding.cc b/libtransmission/port-forwarding.cc index 898857776..aa1fb877e 100644 --- a/libtransmission/port-forwarding.cc +++ b/libtransmission/port-forwarding.cc @@ -161,7 +161,7 @@ static void onTimer(evutil_socket_t /*fd*/, short /*what*/, void* vshared) tr_shared* tr_sharedInit(tr_session* session) { - tr_shared* s = tr_new0(tr_shared, 1); + auto* const s = tr_new0(tr_shared, 1); s->session = session; s->isEnabled = false; diff --git a/libtransmission/ptrarray.cc b/libtransmission/ptrarray.cc index e934187cb..febe0646c 100644 --- a/libtransmission/ptrarray.cc +++ b/libtransmission/ptrarray.cc @@ -14,7 +14,7 @@ #include "tr-macros.h" #include "utils.h" -#define FLOOR 32 +static auto constexpr Floor = int{ 32 }; int tr_lowerBound( void const* key, @@ -89,7 +89,7 @@ int tr_ptrArrayInsert(tr_ptrArray* t, void* ptr, int pos) { if (t->n_items >= t->n_alloc) { - t->n_alloc = std::max(FLOOR, t->n_alloc * 2); + t->n_alloc = std::max(Floor, t->n_alloc * 2); t->items = tr_renew(void*, t->items, t->n_alloc); } diff --git a/libtransmission/rpc-server.cc b/libtransmission/rpc-server.cc index 9e2bd6862..317993c97 100644 --- a/libtransmission/rpc-server.cc +++ b/libtransmission/rpc-server.cc @@ -52,10 +52,11 @@ using namespace std::literals; * http://www.webappsec.org/lists/websecurity/archive/2008-04/msg00037.html */ #define REQUIRE_SESSION_ID -#define MY_NAME "RPC Server" +static char constexpr MyName[] = "RPC Server"; + #define MY_REALM "Transmission" -#define dbgmsg(...) tr_logAddDeepNamed(MY_NAME, __VA_ARGS__) +#define dbgmsg(...) tr_logAddDeepNamed(MyName, __VA_ARGS__) static int constexpr DeflateLevel = 6; // medium / default @@ -99,8 +100,8 @@ static auto extract_parts_from_multipart(struct evkeyvalq const* headers, struct { auto ret = std::vector{}; - char const* content_type = evhttp_find_header(headers, "Content-Type"); - char const* in = (char const*)evbuffer_pullup(body, -1); + auto const* const content_type = evhttp_find_header(headers, "Content-Type"); + auto const* in = (char const*)evbuffer_pullup(body, -1); size_t inlen = evbuffer_get_length(body); char const* boundary_key = "boundary="; @@ -453,7 +454,7 @@ static void handle_rpc(struct evhttp_request* req, tr_rpc_server* server) if (q != nullptr) { - struct rpc_response_data* data = tr_new0(struct rpc_response_data, 1); + auto* const data = tr_new0(struct rpc_response_data, 1); data->req = req; data->server = server; tr_rpc_request_exec_uri(server->session, q + 1, rpc_response_func, data); @@ -746,12 +747,12 @@ static void startServer(void* vserver) { int const retry_delay = rpc_server_start_retry(server); - tr_logAddNamedDbg(MY_NAME, "Unable to bind to %s:%d, retrying in %d seconds", address, port, retry_delay); + tr_logAddNamedDbg(MyName, "Unable to bind to %s:%d, retrying in %d seconds", address, port, retry_delay); return; } tr_logAddNamedError( - MY_NAME, + MyName, "Unable to bind to %s:%d after %d attempts, giving up", address, port, @@ -762,7 +763,7 @@ static void startServer(void* vserver) evhttp_set_gencb(httpd, handle_request, server); server->httpd = httpd; - tr_logAddNamedDbg(MY_NAME, "Started listening on %s:%d", address, port); + tr_logAddNamedDbg(MyName, "Started listening on %s:%d", address, port); } rpc_server_start_retry_cancel(server); @@ -787,7 +788,7 @@ static void stopServer(tr_rpc_server* server) server->httpd = nullptr; evhttp_free(httpd); - tr_logAddNamedDbg(MY_NAME, "Stopped listening on %s:%d", address, port); + tr_logAddNamedDbg(MyName, "Stopped listening on %s:%d", address, port); } static void onEnabledChanged(void* vserver) @@ -872,13 +873,13 @@ static auto parseWhitelist(std::string_view whitelist) if (token.find_first_of("+-"sv) != token.npos) { tr_logAddNamedInfo( - MY_NAME, + MyName, "Adding address to whitelist: %" TR_PRIsv " (And it has a '+' or '-'! Are you using an old ACL by mistake?)", TR_PRIsv_ARG(token)); } else { - tr_logAddNamedInfo(MY_NAME, "Adding address to whitelist: %" TR_PRIsv, TR_PRIsv_ARG(token)); + tr_logAddNamedInfo(MyName, "Adding address to whitelist: %" TR_PRIsv, TR_PRIsv_ARG(token)); } } @@ -995,7 +996,7 @@ void tr_rpcSetAntiBruteForceThreshold(tr_rpc_server* server, int badRequests) static void missing_settings_key(tr_quark const q) { char const* str = tr_quark_get_string(q); - tr_logAddNamedError(MY_NAME, _("Couldn't find settings key \"%s\""), str); + tr_logAddNamedError(MyName, _("Couldn't find settings key \"%s\""), str); } tr_rpc_server::tr_rpc_server(tr_session* session_in, tr_variant* settings) @@ -1154,13 +1155,13 @@ tr_rpc_server::tr_rpc_server(tr_session* session_in, tr_variant* settings) { if (!tr_address_from_string(&address, std::string{ sv }.c_str())) { - tr_logAddNamedError(MY_NAME, _("%" TR_PRIsv " is not a valid address"), TR_PRIsv_ARG(sv)); + tr_logAddNamedError(MyName, _("%" TR_PRIsv " is not a valid address"), TR_PRIsv_ARG(sv)); address = tr_inaddr_any; } else if (address.type != TR_AF_INET && address.type != TR_AF_INET6) { tr_logAddNamedError( - MY_NAME, + MyName, _("%" TR_PRIsv " is not an IPv4 or IPv6 address. RPC listeners must be IPv4 or IPv6"), TR_PRIsv_ARG(sv)); address = tr_inaddr_any; @@ -1172,7 +1173,7 @@ tr_rpc_server::tr_rpc_server(tr_session* session_in, tr_variant* settings) if (this->isEnabled) { tr_logAddNamedInfo( - MY_NAME, + MyName, _("Serving RPC and Web requests on %s:%d%s"), tr_rpcGetBindAddress(this), (int)this->port, @@ -1181,19 +1182,19 @@ tr_rpc_server::tr_rpc_server(tr_session* session_in, tr_variant* settings) if (this->isWhitelistEnabled) { - tr_logAddNamedInfo(MY_NAME, "%s", _("Whitelist enabled")); + tr_logAddNamedInfo(MyName, "%s", _("Whitelist enabled")); } if (this->isPasswordEnabled) { - tr_logAddNamedInfo(MY_NAME, "%s", _("Password required")); + tr_logAddNamedInfo(MyName, "%s", _("Password required")); } } char const* webClientDir = tr_getWebClientDir(this->session); if (!tr_str_is_empty(webClientDir)) { - tr_logAddNamedInfo(MY_NAME, _("Serving RPC and Web requests from directory '%s'"), webClientDir); + tr_logAddNamedInfo(MyName, _("Serving RPC and Web requests from directory '%s'"), webClientDir); } } diff --git a/libtransmission/rpcimpl.cc b/libtransmission/rpcimpl.cc index 3b7fa04fe..e094c0100 100644 --- a/libtransmission/rpcimpl.cc +++ b/libtransmission/rpcimpl.cc @@ -483,7 +483,7 @@ static void addPeers(tr_torrent const* tor, tr_variant* list) tr_torrentPeersFree(peers, peerCount); } -static void initField(tr_torrent* const tor, tr_stat const* const st, tr_variant* const initme, tr_quark key) +static void initField(tr_torrent const* const tor, tr_stat const* const st, tr_variant* const initme, tr_quark key) { char* str = nullptr; @@ -1135,7 +1135,7 @@ static char const* torrentSet( if (tr_variantDictFindInt(args_in, TR_KEY_bandwidthPriority, &tmp)) { - tr_priority_t const priority = (tr_priority_t)tmp; + auto const priority = tr_priority_t(tmp); if (tr_isPriority(priority)) { @@ -2444,7 +2444,7 @@ void tr_rpc_request_exec_json( } else { - struct tr_rpc_idle_data* data = tr_new0(struct tr_rpc_idle_data, 1); + auto* const data = tr_new0(struct tr_rpc_idle_data, 1); data->session = session; data->response = tr_new0(tr_variant, 1); tr_variantInitDict(data->response, 3); diff --git a/libtransmission/session-id.cc b/libtransmission/session-id.cc index b3c63ed4a..750c9cdc8 100644 --- a/libtransmission/session-id.cc +++ b/libtransmission/session-id.cc @@ -25,8 +25,8 @@ using namespace std::literals; -#define SESSION_ID_SIZE 48 -#define SESSION_ID_DURATION_SEC (60 * 60) /* expire in an hour */ +static auto constexpr SessionIdSize = size_t{ 48 }; +static auto constexpr SessionIdDurationSec = time_t{ 60 * 60 }; /* expire in an hour */ struct tr_session_id { @@ -42,16 +42,16 @@ static char* generate_new_session_id_value(void) char const pool[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; size_t const pool_size = sizeof(pool) - 1; - char* buf = tr_new(char, SESSION_ID_SIZE + 1); + auto* buf = tr_new(char, SessionIdSize + 1); - tr_rand_buffer(buf, SESSION_ID_SIZE); + tr_rand_buffer(buf, SessionIdSize); - for (size_t i = 0; i < SESSION_ID_SIZE; ++i) + for (size_t i = 0; i < SessionIdSize; ++i) { buf[i] = pool[(unsigned char)buf[i] % pool_size]; } - buf[SESSION_ID_SIZE] = '\0'; + buf[SessionIdSize] = '\0'; return buf; } @@ -117,7 +117,7 @@ static void destroy_session_id_lock_file(tr_sys_file_t lock_file, char const* se tr_session_id_t tr_session_id_new(void) { - tr_session_id_t const session_id = tr_new0(struct tr_session_id, 1); + auto const session_id = tr_new0(struct tr_session_id, 1); session_id->current_lock_file = TR_BAD_SYS_FILE; session_id->previous_lock_file = TR_BAD_SYS_FILE; @@ -156,7 +156,7 @@ char const* tr_session_id_get_current(tr_session_id_t session_id) session_id->previous_lock_file = session_id->current_lock_file; session_id->current_lock_file = create_session_id_lock_file(session_id->current_value); - session_id->expires_at = now + SESSION_ID_DURATION_SEC; + session_id->expires_at = now + SessionIdDurationSec; } return session_id->current_value; diff --git a/libtransmission/session.cc b/libtransmission/session.cc index a47937a4a..630f425bd 100644 --- a/libtransmission/session.cc +++ b/libtransmission/session.cc @@ -1934,13 +1934,13 @@ static bool deadlineReached(time_t const deadline) return time(nullptr) >= deadline; } -#define SHUTDOWN_MAX_SECONDS 20 +static auto constexpr ShutdownMaxSeconds = time_t{ 20 }; void tr_sessionClose(tr_session* session) { TR_ASSERT(tr_isSession(session)); - time_t const deadline = time(nullptr) + SHUTDOWN_MAX_SECONDS; + time_t const deadline = time(nullptr) + ShutdownMaxSeconds; dbgmsg( "shutting down transmission session %p... now is %zu, deadline is %zu", @@ -2810,7 +2810,7 @@ int tr_sessionCountQueueFreeSlots(tr_session* session, tr_direction dir) /* is it stalled? */ if (stalled_enabled) { - int const idle_secs = (int)difftime(now, std::max(tor->startDate, tor->activityDate)); + auto const idle_secs = int(difftime(now, std::max(tor->startDate, tor->activityDate))); if (idle_secs >= stalled_if_idle_for_n_seconds) continue; } diff --git a/libtransmission/stats.cc b/libtransmission/stats.cc index 45dbab1c6..38610c547 100644 --- a/libtransmission/stats.cc +++ b/libtransmission/stats.cc @@ -114,7 +114,7 @@ static void saveCumulativeStats(tr_session const* session, tr_session_stats cons void tr_statsInit(tr_session* session) { - struct tr_stats_handle* stats = tr_new0(struct tr_stats_handle, 1); + auto* const stats = tr_new0(struct tr_stats_handle, 1); loadCumulativeStats(session, &stats->old); stats->single.sessionCount = 1; diff --git a/libtransmission/torrent-magnet.cc b/libtransmission/torrent-magnet.cc index 4c2b1e27b..edd4e7318 100644 --- a/libtransmission/torrent-magnet.cc +++ b/libtransmission/torrent-magnet.cc @@ -86,7 +86,7 @@ bool tr_torrentSetMetadataSizeHint(tr_torrent* tor, int64_t size) return false; } - struct tr_incomplete_metadata* m = tr_new(struct tr_incomplete_metadata, 1); + auto* const m = tr_new(struct tr_incomplete_metadata, 1); if (m == nullptr) { @@ -115,7 +115,7 @@ bool tr_torrentSetMetadataSizeHint(tr_torrent* tor, int64_t size) return true; } -void* tr_torrentGetMetadataPiece(tr_torrent* tor, int piece, size_t* len) +void* tr_torrentGetMetadataPiece(tr_torrent const* tor, int piece, size_t* len) { TR_ASSERT(tr_isTorrent(tor)); TR_ASSERT(piece >= 0); @@ -142,7 +142,7 @@ void* tr_torrentGetMetadataPiece(tr_torrent* tor, int piece, size_t* len) if (0 < l && l <= METADATA_PIECE_SIZE) { - char* buf = tr_new(char, l); + auto* buf = tr_new(char, l); auto n = uint64_t{}; if (tr_sys_file_read(fd, buf, l, &n, nullptr) && n == l) @@ -240,19 +240,23 @@ static void tr_buildMetainfoExceptInfoDict(tr_torrent_metainfo const& tm, tr_var } } -static bool useNewMetainfo(tr_torrent* tor, tr_incomplete_metadata* m, tr_error** error) +static bool useNewMetainfo(tr_torrent* tor, tr_incomplete_metadata const* m, tr_error** error) { + // test the info_dict checksum auto const sha1 = tr_sha1(std::string_view{ m->metadata, m->metadata_size }); - bool const checksum_passed = sha1 && *sha1 == tor->infoHash(); - if (!checksum_passed) + if (bool const checksum_passed = sha1 && *sha1 == tor->infoHash(); !checksum_passed) { return false; } // checksum passed; now try to parse it as benc auto info_dict_v = tr_variant{}; - auto const info_dict_sv = std::string_view{ m->metadata, m->metadata_size }; - if (!tr_variantFromBuf(&info_dict_v, TR_VARIANT_PARSE_BENC | TR_VARIANT_PARSE_INPLACE, info_dict_sv, nullptr, error)) + if (!tr_variantFromBuf( + &info_dict_v, + TR_VARIANT_PARSE_BENC | TR_VARIANT_PARSE_INPLACE, + { m->metadata, m->metadata_size }, + nullptr, + error)) { return false; } diff --git a/libtransmission/torrent-magnet.h b/libtransmission/torrent-magnet.h index 805692308..2db718859 100644 --- a/libtransmission/torrent-magnet.h +++ b/libtransmission/torrent-magnet.h @@ -23,7 +23,7 @@ struct tr_torrent; // defined by BEP #9 inline constexpr int METADATA_PIECE_SIZE = 1024 * 16; -void* tr_torrentGetMetadataPiece(tr_torrent* tor, int piece, size_t* len); +void* tr_torrentGetMetadataPiece(tr_torrent const* tor, int piece, size_t* len); void tr_torrentSetMetadataPiece(tr_torrent* tor, int piece, void const* data, int len); diff --git a/libtransmission/torrent.cc b/libtransmission/torrent.cc index 2e1583f92..35febd157 100644 --- a/libtransmission/torrent.cc +++ b/libtransmission/torrent.cc @@ -560,8 +560,7 @@ static void tr_torrentFireMetadataCompleted(tr_torrent* tor); static void torrentInitFromInfoDict(tr_torrent* tor) { tor->completion = tr_completion{ tor, &tor->blockInfo() }; - auto const obfuscated = tr_sha1("req2"sv, tor->infoHash()); - if (obfuscated) + if (auto const obfuscated = tr_sha1("req2"sv, tor->infoHash()); obfuscated) { tor->obfuscated_hash = *obfuscated; } @@ -2151,7 +2150,7 @@ static void removeEmptyFoldersAndJunkFiles(char const* folder) * 2. If there are nontorrent files, don't delete them... * 3. ...unless the other files are "junk", such as .DS_Store */ -static void deleteLocalData(tr_torrent* tor, tr_fileFunc func) +static void deleteLocalData(tr_torrent const* tor, tr_fileFunc func) { auto files = std::vector{}; auto folders = std::set{}; @@ -2852,7 +2851,7 @@ static bool renameArgsAreValid(char const* oldpath, char const* newname) strchr(newname, TR_PATH_DELIMITER) == nullptr; } -static auto renameFindAffectedFiles(tr_torrent* tor, std::string_view oldpath) +static auto renameFindAffectedFiles(tr_torrent const* tor, std::string_view oldpath) { auto indices = std::vector{}; auto oldpath_as_dir = tr_strvJoin(oldpath, "/"sv); diff --git a/libtransmission/tr-utp.cc b/libtransmission/tr-utp.cc index 8650e9c28..513899ad6 100644 --- a/libtransmission/tr-utp.cc +++ b/libtransmission/tr-utp.cc @@ -38,25 +38,25 @@ THE SOFTWARE. #ifndef WITH_UTP -#define MY_NAME "UTP" +static char constexpr MyName[] = "UTP"; -#define dbgmsg(...) tr_logAddDeepNamed(MY_NAME, __VA_ARGS__) +#define dbgmsg(...) tr_logAddDeepNamed(MyName, __VA_ARGS__) void UTP_Close(struct UTPSocket* socket) { - tr_logAddNamedError(MY_NAME, "UTP_Close(%p) was called.", socket); + tr_logAddNamedError(MyName, "UTP_Close(%p) was called.", socket); dbgmsg("UTP_Close(%p) was called.", socket); } void UTP_RBDrained(struct UTPSocket* socket) { - tr_logAddNamedError(MY_NAME, "UTP_RBDrained(%p) was called.", socket); + tr_logAddNamedError(MyName, "UTP_RBDrained(%p) was called.", socket); dbgmsg("UTP_RBDrained(%p) was called.", socket); } bool UTP_Write(struct UTPSocket* socket, size_t count) { - tr_logAddNamedError(MY_NAME, "UTP_RBDrained(%p, %zu) was called.", socket, count); + tr_logAddNamedError(MyName, "UTP_RBDrained(%p, %zu) was called.", socket, count); dbgmsg("UTP_RBDrained(%p, %zu) was called.", socket, count); return false; } @@ -97,14 +97,13 @@ void tr_utpSendTo( #else /* Greg says 50ms works for them. */ - -#define UTP_INTERVAL_US 50000 +static auto constexpr UtpIntervalUs = int{ 50000 }; static void incoming(void* vsession, struct UTPSocket* s) { auto* session = static_cast(vsession); struct sockaddr_storage from_storage; - struct sockaddr* from = (struct sockaddr*)&from_storage; + auto* const from = (struct sockaddr*)&from_storage; socklen_t fromlen = sizeof(from_storage); tr_address addr; tr_port port = 0; @@ -149,7 +148,7 @@ static void reset_timer(tr_session* ss) if (tr_sessionIsUTPEnabled(ss)) { sec = 0; - usec = UTP_INTERVAL_US / 2 + tr_rand_int_weak(UTP_INTERVAL_US); + usec = UtpIntervalUs / 2 + tr_rand_int_weak(UtpIntervalUs); } else { diff --git a/libtransmission/upnp.cc b/libtransmission/upnp.cc index debb96c3b..2deb9b120 100644 --- a/libtransmission/upnp.cc +++ b/libtransmission/upnp.cc @@ -55,7 +55,7 @@ struct tr_upnp tr_upnp* tr_upnpInit(void) { - tr_upnp* ret = tr_new0(tr_upnp, 1); + auto* const ret = tr_new0(tr_upnp, 1); ret->state = TR_UPNP_DISCOVER; ret->port = -1; diff --git a/libtransmission/utils.cc b/libtransmission/utils.cc index 822a0cb29..eea48f8c8 100644 --- a/libtransmission/utils.cc +++ b/libtransmission/utils.cc @@ -770,7 +770,7 @@ bool tr_utf8_validate(std::string_view sv, char const** good_end) static char* strip_non_utf8(std::string_view sv) { - char* ret = tr_new(char, std::size(sv) + 1); + auto* const ret = tr_new(char, std::size(sv) + 1); if (ret != nullptr) { auto const it = utf8::unchecked::replace_invalid(std::data(sv), std::data(sv) + std::size(sv), ret, '?'); @@ -783,7 +783,7 @@ static char* to_utf8(std::string_view sv) { #ifdef HAVE_ICONV size_t const buflen = std::size(sv) * 4 + 10; - char* out = tr_new(char, buflen); + auto* const out = tr_new(char, buflen); auto constexpr Encodings = std::array{ "CURRENT", "ISO-8859-15" }; for (auto const* test_encoding : Encodings) diff --git a/libtransmission/variant-json.cc b/libtransmission/variant-json.cc index 96dc65142..06c5a57cf 100644 --- a/libtransmission/variant-json.cc +++ b/libtransmission/variant-json.cc @@ -32,7 +32,7 @@ using namespace std::literals; /* arbitrary value... this is much deeper than our code goes */ -#define MAX_DEPTH 64 +static auto constexpr MaxDepth = int{ 64 }; struct json_wrapper_data { @@ -49,7 +49,7 @@ struct json_wrapper_data * e.g. they may all be objects with the same set of keys. So when * a container is popped off the stack, remember its size to use as * a preallocation heuristic for the next container at that depth. */ - std::array preallocGuess; + std::array preallocGuess; }; static tr_variant* get_node(struct jsonsl_st* jsn) @@ -106,7 +106,7 @@ static void action_callback_PUSH( data->stack.push_back(node); int const depth = std::size(data->stack); - size_t const n = depth < MAX_DEPTH ? data->preallocGuess[depth] : 0; + size_t const n = depth < MaxDepth ? data->preallocGuess[depth] : 0; if (state->type == JSONSL_T_LIST) { tr_variantInitList(node, n); @@ -307,7 +307,7 @@ static void action_callback_POP( int const depth = std::size(data->stack); auto* v = data->stack.back(); data->stack.pop_back(); - if (depth < MAX_DEPTH) + if (depth < MaxDepth) { data->preallocGuess[depth] = v->val.l.count; } @@ -346,7 +346,7 @@ int tr_variantParseJson(tr_variant& setme, int parse_opts, std::string_view benc auto data = json_wrapper_data{}; - jsonsl_t jsn = jsonsl_new(MAX_DEPTH); + jsonsl_t jsn = jsonsl_new(MaxDepth); jsn->action_callback_PUSH = action_callback_PUSH; jsn->action_callback_POP = action_callback_POP; jsn->error_callback = error_callback; diff --git a/libtransmission/watchdir-generic.cc b/libtransmission/watchdir-generic.cc index 64a7b1027..f00cd3511 100644 --- a/libtransmission/watchdir-generic.cc +++ b/libtransmission/watchdir-generic.cc @@ -53,14 +53,14 @@ auto tr_watchdir_generic_interval = timeval{ 10, 0 }; static void tr_watchdir_generic_on_event(evutil_socket_t /*fd*/, short /*type*/, void* context) { auto const handle = static_cast(context); - tr_watchdir_generic* const backend = BACKEND_UPCAST(tr_watchdir_get_backend(handle)); + auto* const backend = BACKEND_UPCAST(tr_watchdir_get_backend(handle)); tr_watchdir_scan(handle, &backend->dir_entries); } static void tr_watchdir_generic_free(tr_watchdir_backend* backend_base) { - tr_watchdir_generic* const backend = BACKEND_UPCAST(backend_base); + auto* const backend = BACKEND_UPCAST(backend_base); if (backend == nullptr) { diff --git a/libtransmission/watchdir-inotify.cc b/libtransmission/watchdir-inotify.cc index a0158dcb4..adf07463c 100644 --- a/libtransmission/watchdir-inotify.cc +++ b/libtransmission/watchdir-inotify.cc @@ -71,7 +71,7 @@ static void tr_watchdir_inotify_on_event(struct bufferevent* event, void* contex #endif struct inotify_event ev; size_t name_size = NAME_MAX + 1; - char* name = tr_new(char, name_size); + auto* name = tr_new(char, name_size); /* Read the size of the struct excluding name into buf. Guaranteed to have at least sizeof(ev) available */ @@ -121,7 +121,7 @@ static void tr_watchdir_inotify_on_event(struct bufferevent* event, void* contex static void tr_watchdir_inotify_free(tr_watchdir_backend* backend_base) { - tr_watchdir_inotify* const backend = BACKEND_UPCAST(backend_base); + auto* const backend = BACKEND_UPCAST(backend_base); if (backend == nullptr) { diff --git a/qt/DetailsDialog.cc b/qt/DetailsDialog.cc index d7a4fe1a2..fd99c0b69 100644 --- a/qt/DetailsDialog.cc +++ b/qt/DetailsDialog.cc @@ -1037,7 +1037,7 @@ void DetailsDialog::refreshUI() for (Peer const& peer : peers) { QString const key = id_str + QLatin1Char(':') + peer.address; - PeerItem* item = static_cast(peers_.value(key, nullptr)); + auto* item = static_cast(peers_.value(key, nullptr)); if (item == nullptr) // new peer has connected { diff --git a/utils/remote.cc b/utils/remote.cc index 754e97a1c..b9ce15377 100644 --- a/utils/remote.cc +++ b/utils/remote.cc @@ -2375,7 +2375,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv) } else if (stepMode == MODE_TORRENT_GET) { - tr_variant* top = tr_new0(tr_variant, 1); + auto* top = tr_new0(tr_variant, 1); tr_variant* args; tr_variant* fields; tr_variantInitDict(top, 3); @@ -2807,11 +2807,10 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv) } else { - tr_variant* args; - tr_variant* top = tr_new0(tr_variant, 1); + auto* top = tr_new0(tr_variant, 1); tr_variantInitDict(top, 2); tr_variantDictAddStrView(top, TR_KEY_method, "torrent-set-location"sv); - args = tr_variantDictAddDict(top, Arguments, 3); + tr_variant* args = tr_variantDictAddDict(top, Arguments, 3); tr_variantDictAddStr(args, TR_KEY_location, optarg); tr_variantDictAddBool(args, TR_KEY_move, false); addIdArg(args, id, nullptr); @@ -2825,7 +2824,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv) { case 920: /* session-info */ { - tr_variant* top = tr_new0(tr_variant, 1); + auto* top = tr_new0(tr_variant, 1); tr_variantInitDict(top, 2); tr_variantDictAddStrView(top, TR_KEY_method, "session-get"sv); tr_variantDictAddInt(top, TR_KEY_tag, TAG_SESSION); @@ -2841,7 +2840,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv) } else { - tr_variant* top = tr_new0(tr_variant, 1); + auto* top = tr_new0(tr_variant, 1); tr_variantInitDict(top, 2); tr_variantDictAddStrView(top, TR_KEY_method, "torrent-start"sv); addIdArg(tr_variantDictAddDict(top, Arguments, 1), id, nullptr); @@ -2859,7 +2858,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv) } else { - tr_variant* top = tr_new0(tr_variant, 1); + auto* top = tr_new0(tr_variant, 1); tr_variantInitDict(top, 2); tr_variantDictAddStrView(top, TR_KEY_method, "torrent-stop"sv); addIdArg(tr_variantDictAddDict(top, Arguments, 1), id, nullptr); @@ -2878,7 +2877,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv) case 850: { - tr_variant* top = tr_new0(tr_variant, 1); + auto* top = tr_new0(tr_variant, 1); tr_variantInitDict(top, 1); tr_variantDictAddStrView(top, TR_KEY_method, "session-close"sv); status |= flush(rpcurl, &top); @@ -2887,7 +2886,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv) case 963: { - tr_variant* top = tr_new0(tr_variant, 1); + auto* top = tr_new0(tr_variant, 1); tr_variantInitDict(top, 1); tr_variantDictAddStrView(top, TR_KEY_method, "blocklist-update"sv); status |= flush(rpcurl, &top); @@ -2896,7 +2895,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv) case 921: { - tr_variant* top = tr_new0(tr_variant, 1); + auto* top = tr_new0(tr_variant, 1); tr_variantInitDict(top, 2); tr_variantDictAddStrView(top, TR_KEY_method, "session-stats"sv); tr_variantDictAddInt(top, TR_KEY_tag, TAG_STATS); @@ -2906,7 +2905,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv) case 962: { - tr_variant* top = tr_new0(tr_variant, 1); + auto* top = tr_new0(tr_variant, 1); tr_variantInitDict(top, 2); tr_variantDictAddStrView(top, TR_KEY_method, "port-test"sv); tr_variantDictAddInt(top, TR_KEY_tag, TAG_PORTTEST); @@ -2916,15 +2915,13 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv) case 600: { - tr_variant* top; - if (tset != nullptr) { addIdArg(tr_variantDictFind(tset, Arguments), id, nullptr); status |= flush(rpcurl, &tset); } - top = tr_new0(tr_variant, 1); + auto* top = tr_new0(tr_variant, 1); tr_variantInitDict(top, 2); tr_variantDictAddStrView(top, TR_KEY_method, "torrent-reannounce"sv); addIdArg(tr_variantDictAddDict(top, Arguments, 1), id, nullptr); @@ -2934,15 +2931,13 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv) case 'v': { - tr_variant* top; - if (tset != nullptr) { addIdArg(tr_variantDictFind(tset, Arguments), id, nullptr); status |= flush(rpcurl, &tset); } - top = tr_new0(tr_variant, 1); + auto* top = tr_new0(tr_variant, 1); tr_variantInitDict(top, 2); tr_variantDictAddStrView(top, TR_KEY_method, "torrent-verify"sv); addIdArg(tr_variantDictAddDict(top, Arguments, 1), id, nullptr); @@ -2953,11 +2948,10 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv) case 'r': case 840: { - tr_variant* args; - tr_variant* top = tr_new0(tr_variant, 1); + auto* top = tr_new0(tr_variant, 1); tr_variantInitDict(top, 2); tr_variantDictAddStrView(top, TR_KEY_method, "torrent-remove"sv); - args = tr_variantDictAddDict(top, Arguments, 2); + auto* args = tr_variantDictAddDict(top, Arguments, 2); tr_variantDictAddBool(args, TR_KEY_delete_local_data, c == 840); addIdArg(args, id, nullptr); status |= flush(rpcurl, &top); @@ -2966,11 +2960,10 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv) case 960: { - tr_variant* args; - tr_variant* top = tr_new0(tr_variant, 1); + auto* top = tr_new0(tr_variant, 1); tr_variantInitDict(top, 2); tr_variantDictAddStrView(top, TR_KEY_method, "torrent-set-location"sv); - args = tr_variantDictAddDict(top, Arguments, 3); + auto* args = tr_variantDictAddDict(top, Arguments, 3); tr_variantDictAddStr(args, TR_KEY_location, optarg); tr_variantDictAddBool(args, TR_KEY_move, true); addIdArg(args, id, nullptr); @@ -3013,7 +3006,7 @@ static bool parsePortString(char const* s, int* port) errno = 0; char* end = nullptr; - int const i = (int)strtol(s, &end, 10); + auto const i = int(strtol(s, &end, 10)); bool const ok = (end != nullptr) && (*end == '\0') && (errno == 0); if (ok) { diff --git a/utils/show.cc b/utils/show.cc index ace9dfd1e..d757869e4 100644 --- a/utils/show.cc +++ b/utils/show.cc @@ -263,7 +263,7 @@ void doScrape(tr_torrent_metainfo const& metainfo) // print it out tr_variant top; - char const* begin = (char const*)evbuffer_pullup(buf, -1); + 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)) {