mirror of
https://github.com/transmission/transmission
synced 2025-03-15 16:29:34 +00:00
fix: sonarcloud warnings in new code (#2500)
This commit is contained in:
parent
e83a57efa3
commit
ac823f3cc4
7 changed files with 60 additions and 68 deletions
|
@ -1373,7 +1373,7 @@ static void multiscrape(tr_announcer* announcer, std::vector<tr_tier*> const& ti
|
|||
// batch as many info_hashes into a request as we can
|
||||
for (auto* tier : tiers)
|
||||
{
|
||||
auto* const scrape_info = tier->currentTracker()->scrape_info;
|
||||
auto const* const scrape_info = tier->currentTracker()->scrape_info;
|
||||
bool found = false;
|
||||
|
||||
TR_ASSERT(scrape_info != nullptr);
|
||||
|
|
|
@ -31,6 +31,8 @@ std::optional<std::string_view> ParseString(std::string_view* benc);
|
|||
|
||||
struct Handler
|
||||
{
|
||||
virtual ~Handler() = default;
|
||||
|
||||
virtual bool Int64(int64_t) = 0;
|
||||
virtual bool String(std::string_view) = 0;
|
||||
|
||||
|
@ -197,24 +199,21 @@ bool parse(
|
|||
switch (benc.front())
|
||||
{
|
||||
case 'i': // int
|
||||
if (auto const value = impl::ParseInt(&benc); !value)
|
||||
{
|
||||
auto const value = impl::ParseInt(&benc);
|
||||
if (!value)
|
||||
{
|
||||
tr_error_set(error, err, "Malformed benc? Unable to parse integer");
|
||||
break;
|
||||
}
|
||||
|
||||
if (!handler.Int64(*value))
|
||||
{
|
||||
err = ECANCELED;
|
||||
tr_error_set(error, err, "Handler indicated parser should stop");
|
||||
break;
|
||||
}
|
||||
|
||||
stack.tokenWalked();
|
||||
break;
|
||||
tr_error_set(error, err, "Malformed benc? Unable to parse integer");
|
||||
}
|
||||
else if (!handler.Int64(*value))
|
||||
{
|
||||
err = ECANCELED;
|
||||
tr_error_set(error, err, "Handler indicated parser should stop");
|
||||
}
|
||||
else
|
||||
{
|
||||
stack.tokenWalked();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'l': // list
|
||||
case 'd': // dict
|
||||
{
|
||||
|
@ -238,29 +237,25 @@ bool parse(
|
|||
break;
|
||||
}
|
||||
case 'e': // end of list or dict
|
||||
benc.remove_prefix(1);
|
||||
|
||||
if (auto const parent_type = stack.pop(error); !parent_type)
|
||||
{
|
||||
err = EILSEQ;
|
||||
}
|
||||
else
|
||||
{
|
||||
benc.remove_prefix(1);
|
||||
|
||||
auto const parent_type = stack.pop(error);
|
||||
if (!parent_type)
|
||||
{
|
||||
err = EILSEQ;
|
||||
break;
|
||||
}
|
||||
|
||||
stack.tokenWalked();
|
||||
|
||||
bool ok = *parent_type == ParserStack<MaxDepth>::ParentType::Array ? handler.EndArray() : handler.EndDict();
|
||||
|
||||
if (!ok)
|
||||
if (auto const ok = *parent_type == ParserStack<MaxDepth>::ParentType::Array ? handler.EndArray() :
|
||||
handler.EndDict();
|
||||
!ok)
|
||||
{
|
||||
err = ECANCELED;
|
||||
tr_error_set(error, err, "Handler indicated parser should stop");
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case '0':
|
||||
case '1':
|
||||
|
@ -272,26 +267,21 @@ bool parse(
|
|||
case '7':
|
||||
case '8':
|
||||
case '9': // string
|
||||
if (auto const sv = impl::ParseString(&benc); !sv)
|
||||
{
|
||||
auto const sv = impl::ParseString(&benc);
|
||||
if (!sv)
|
||||
{
|
||||
err = EILSEQ;
|
||||
tr_error_set(error, err, "Malformed benc? Unable to parse string");
|
||||
break;
|
||||
}
|
||||
|
||||
bool const ok = stack.expectingDictKey() ? handler.Key(*sv) : handler.String(*sv);
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
err = ECANCELED;
|
||||
tr_error_set(error, err, "Handler indicated parser should stop");
|
||||
break;
|
||||
}
|
||||
stack.tokenWalked();
|
||||
break;
|
||||
err = EILSEQ;
|
||||
tr_error_set(error, err, "Malformed benc? Unable to parse string");
|
||||
}
|
||||
else if (bool const ok = stack.expectingDictKey() ? handler.Key(*sv) : handler.String(*sv); !ok)
|
||||
{
|
||||
err = ECANCELED;
|
||||
tr_error_set(error, err, "Handler indicated parser should stop");
|
||||
}
|
||||
else
|
||||
{
|
||||
stack.tokenWalked();
|
||||
}
|
||||
break;
|
||||
|
||||
default: // invalid bencoded text... march past it
|
||||
benc.remove_prefix(1);
|
||||
|
|
|
@ -643,10 +643,9 @@ unsigned char const* tr_globalIPv6(tr_session const* session)
|
|||
static unsigned char ipv6[16];
|
||||
static time_t last_time = 0;
|
||||
static bool have_ipv6 = false;
|
||||
time_t const now = tr_time();
|
||||
|
||||
/* Re-check every half hour */
|
||||
if (last_time < now - 1800)
|
||||
if (auto const now = tr_time(); last_time < now - 1800)
|
||||
{
|
||||
int addrlen = 16;
|
||||
int const rc = tr_globalAddress(AF_INET6, ipv6, &addrlen);
|
||||
|
|
|
@ -180,7 +180,6 @@ public:
|
|||
bool endgame = false;
|
||||
|
||||
ActiveRequests active_requests;
|
||||
Wishlist wishlist;
|
||||
|
||||
int interestedCount = 0;
|
||||
int maxPeers = 0;
|
||||
|
@ -559,44 +558,44 @@ std::vector<tr_block_span_t> tr_peerMgrGetNextRequests(tr_torrent* torrent, tr_p
|
|||
{
|
||||
}
|
||||
|
||||
~PeerInfoImpl() final = default;
|
||||
~PeerInfoImpl() override = default;
|
||||
|
||||
[[nodiscard]] bool clientCanRequestBlock(tr_block_index_t block) const final
|
||||
[[nodiscard]] bool clientCanRequestBlock(tr_block_index_t block) const override
|
||||
{
|
||||
return !torrent_->hasBlock(block) && !swarm_->active_requests.has(block, peer_);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool clientCanRequestPiece(tr_piece_index_t piece) const final
|
||||
[[nodiscard]] bool clientCanRequestPiece(tr_piece_index_t piece) const override
|
||||
{
|
||||
return torrent_->pieceIsWanted(piece) && peer_->have.test(piece);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool isEndgame() const final
|
||||
[[nodiscard]] bool isEndgame() const override
|
||||
{
|
||||
return swarm_->endgame;
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t countActiveRequests(tr_block_index_t block) const final
|
||||
[[nodiscard]] size_t countActiveRequests(tr_block_index_t block) const override
|
||||
{
|
||||
return swarm_->active_requests.count(block);
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t countMissingBlocks(tr_piece_index_t piece) const final
|
||||
[[nodiscard]] size_t countMissingBlocks(tr_piece_index_t piece) const override
|
||||
{
|
||||
return torrent_->countMissingBlocksInPiece(piece);
|
||||
}
|
||||
|
||||
[[nodiscard]] tr_block_span_t blockSpan(tr_piece_index_t piece) const final
|
||||
[[nodiscard]] tr_block_span_t blockSpan(tr_piece_index_t piece) const override
|
||||
{
|
||||
return torrent_->blockSpanForPiece(piece);
|
||||
}
|
||||
|
||||
[[nodiscard]] tr_piece_index_t countAllPieces() const final
|
||||
[[nodiscard]] tr_piece_index_t countAllPieces() const override
|
||||
{
|
||||
return torrent_->pieceCount();
|
||||
}
|
||||
|
||||
[[nodiscard]] tr_priority_t priority(tr_piece_index_t piece) const final
|
||||
[[nodiscard]] tr_priority_t priority(tr_piece_index_t piece) const override
|
||||
{
|
||||
return torrent_->piecePriority(piece);
|
||||
}
|
||||
|
@ -609,7 +608,7 @@ std::vector<tr_block_span_t> tr_peerMgrGetNextRequests(tr_torrent* torrent, tr_p
|
|||
|
||||
auto* const swarm = torrent->swarm;
|
||||
updateEndgame(swarm);
|
||||
return swarm->wishlist.next(PeerInfoImpl(torrent, peer), numwant);
|
||||
return Wishlist::next(PeerInfoImpl(torrent, peer), numwant);
|
||||
}
|
||||
|
||||
/****
|
||||
|
|
|
@ -693,7 +693,11 @@ static uint64_t loadFromFile(tr_torrent* tor, uint64_t fieldsToLoad, bool* did_m
|
|||
TR_ASSERT(tr_isTorrent(tor));
|
||||
auto const wasDirty = tor->isDirty;
|
||||
|
||||
auto const migrated = tor->metainfo_.migrateFile(tor->session->resume_dir, tor->name(), tor->infoHashString(), ".resume"sv);
|
||||
auto const migrated = tr_torrent_metainfo::migrateFile(
|
||||
tor->session->resume_dir,
|
||||
tor->name(),
|
||||
tor->infoHashString(),
|
||||
".resume"sv);
|
||||
if (did_migrate_filename != nullptr)
|
||||
{
|
||||
*did_migrate_filename = migrated;
|
||||
|
|
|
@ -683,7 +683,7 @@ static void torrentInit(tr_torrent* tor, tr_ctor const* ctor)
|
|||
|
||||
if (resume_file_was_migrated)
|
||||
{
|
||||
tor->metainfo_.migrateFile(session->torrent_dir, tor->name(), tor->infoHashString(), ".torrent");
|
||||
tr_torrent_metainfo::migrateFile(session->torrent_dir, tor->name(), tor->infoHashString(), ".torrent"sv);
|
||||
}
|
||||
|
||||
tor->completeness = tor->completion.status();
|
||||
|
@ -1539,8 +1539,8 @@ static void closeTorrent(void* vtor)
|
|||
|
||||
if (tor->isDeleting)
|
||||
{
|
||||
tor->metainfo_.removeFile(tor->session->torrent_dir, tor->name(), tor->infoHashString(), ".torrent"sv);
|
||||
tor->metainfo_.removeFile(tor->session->resume_dir, tor->name(), tor->infoHashString(), ".resume"sv);
|
||||
tr_torrent_metainfo::removeFile(tor->session->torrent_dir, tor->name(), tor->infoHashString(), ".torrent"sv);
|
||||
tr_torrent_metainfo::removeFile(tor->session->resume_dir, tor->name(), tor->infoHashString(), ".resume"sv);
|
||||
}
|
||||
|
||||
tor->isRunning = false;
|
||||
|
|
|
@ -138,7 +138,7 @@ struct MyHandler : public transmission::benc::Handler
|
|||
{
|
||||
}
|
||||
|
||||
virtual ~MyHandler() = default;
|
||||
~MyHandler() override = default;
|
||||
|
||||
bool Int64(int64_t value) final
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue