mirror of
https://github.com/transmission/transmission
synced 2025-03-11 14:43:42 +00:00
fix: clang-tidy-15 warnings (#3570)
* fix: bugprone-assignment-in-if-condition warning in tr_bitfield::countFlags() * fix: bugprone-assignment-in-if-condition warning in tr_watchdir_generic_new() * fix: bugprone-assignment-in-if-condition warning in torrentRenamePath() * fix: bugprone-assignment-in-if-condition warning in tr_watchdir_inotify_on_event() * fix: bugprone-assignment-in-if-condition warning in tr_variantWalk() * fix: misc-const-correctness warning in TrackerDelegate::getText() * fix: bugprone-assignment-in-if-condition warning in Session::updateStats() * fix: performance-unnecessary-value-param warning in discoverThreadfunc() * fix: clang-analyzer-core.UndefinedBinaryOperatorResult warning in tr_completion::setHasAll() * fix: clang-analyzer-core.UndefinedBinaryOperatorResult warning in tr_torrentFileCompleted() * fix: silence clang-analyzer-cplusplus.NewDelete warning when using QPointer This appears to be a false positive; added NOLINT
This commit is contained in:
parent
bf8f72e61f
commit
f39826cc59
12 changed files with 61 additions and 57 deletions
|
@ -133,7 +133,8 @@ size_t tr_bitfield::countFlags(size_t begin, size_t end) const noexcept
|
|||
for (size_t i = first_byte + 1; i < walk_end;)
|
||||
{
|
||||
tmp_accum += doPopcount(flags_[i]);
|
||||
if ((i += 2) > walk_end)
|
||||
i += 2;
|
||||
if (i > walk_end)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ public:
|
|||
{
|
||||
if (!isInitialized())
|
||||
{
|
||||
return {};
|
||||
return { 0U, 0U };
|
||||
}
|
||||
|
||||
return { pieceLoc(piece).block, pieceLastLoc(piece).block + 1 };
|
||||
|
@ -78,7 +78,7 @@ public:
|
|||
{
|
||||
if (!isInitialized())
|
||||
{
|
||||
return {};
|
||||
return { 0U, 0U };
|
||||
}
|
||||
|
||||
auto const offset = pieceLoc(piece).byte;
|
||||
|
|
|
@ -177,9 +177,9 @@ void tr_completion::setHasAll() noexcept
|
|||
|
||||
void tr_completion::addPiece(tr_piece_index_t piece)
|
||||
{
|
||||
auto const [begin, end] = block_info_->blockSpanForPiece(piece);
|
||||
auto const span = block_info_->blockSpanForPiece(piece);
|
||||
|
||||
for (tr_block_index_t block = begin; block < end; ++block)
|
||||
for (tr_block_index_t block = span.begin; block < span.end; ++block)
|
||||
{
|
||||
addBlock(block);
|
||||
}
|
||||
|
|
|
@ -2257,13 +2257,13 @@ static void tr_torrentFileCompleted(tr_torrent* tor, tr_file_index_t i)
|
|||
}
|
||||
}
|
||||
|
||||
static void tr_torrentPieceCompleted(tr_torrent* tor, tr_piece_index_t pieceIndex)
|
||||
static void tr_torrentPieceCompleted(tr_torrent* tor, tr_piece_index_t piece_index)
|
||||
{
|
||||
tr_peerMgrPieceCompleted(tor, pieceIndex);
|
||||
tr_peerMgrPieceCompleted(tor, piece_index);
|
||||
|
||||
// if this piece completes any file, invoke the fileCompleted func for it
|
||||
auto const [begin, end] = tor->fpm_.fileSpan(pieceIndex);
|
||||
for (tr_file_index_t file = begin; file < end; ++file)
|
||||
auto const span = tor->fpm_.fileSpan(piece_index);
|
||||
for (auto file = span.begin; file < span.end; ++file)
|
||||
{
|
||||
if (tor->completion.hasBlocks(tr_torGetFileBlockSpan(tor, file)))
|
||||
{
|
||||
|
@ -2631,22 +2631,27 @@ static void torrentRenamePath(
|
|||
{
|
||||
error = EINVAL;
|
||||
}
|
||||
else if ((error = renamePath(tor, oldpath, newname)) == 0)
|
||||
else
|
||||
{
|
||||
/* update tr_info.files */
|
||||
for (auto const& file_index : file_indices)
|
||||
{
|
||||
renameTorrentFileString(tor, oldpath, newname, file_index);
|
||||
}
|
||||
error = renamePath(tor, oldpath, newname);
|
||||
|
||||
/* update tr_info.name if user changed the toplevel */
|
||||
if (std::size(file_indices) == tor->fileCount() && !tr_strvContains(oldpath, '/'))
|
||||
if (error == 0)
|
||||
{
|
||||
tor->setName(newname);
|
||||
}
|
||||
/* update tr_info.files */
|
||||
for (auto const& file_index : file_indices)
|
||||
{
|
||||
renameTorrentFileString(tor, oldpath, newname, file_index);
|
||||
}
|
||||
|
||||
tor->markEdited();
|
||||
tor->setDirty();
|
||||
/* update tr_info.name if user changed the toplevel */
|
||||
if (std::size(file_indices) == tor->fileCount() && !tr_strvContains(oldpath, '/'))
|
||||
{
|
||||
tor->setName(newname);
|
||||
}
|
||||
|
||||
tor->markEdited();
|
||||
tor->setDirty();
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
|
|
|
@ -240,7 +240,7 @@ enum
|
|||
UPNP_IGD_INVALID = 3
|
||||
};
|
||||
|
||||
static auto* discoverThreadfunc(std::string bindaddr)
|
||||
static auto* discoverThreadfunc(std::string bindaddr) // NOLINT performance-unnecessary-value-param
|
||||
{
|
||||
return tr_upnpDiscover(2000, bindaddr.c_str());
|
||||
}
|
||||
|
|
|
@ -822,26 +822,32 @@ void tr_variantWalk(tr_variant const* v_in, struct VariantWalkFuncs const* walkF
|
|||
if (!node.is_visited)
|
||||
{
|
||||
v = &node.v;
|
||||
|
||||
node.is_visited = true;
|
||||
}
|
||||
else if ((v = node.nextChild()) != nullptr)
|
||||
else
|
||||
{
|
||||
if (tr_variantIsDict(&node.v))
|
||||
{
|
||||
auto tmp = tr_variant{};
|
||||
tr_variantInitQuark(&tmp, v->key);
|
||||
walkFuncs->stringFunc(&tmp, user_data);
|
||||
}
|
||||
}
|
||||
else // finished with this node
|
||||
{
|
||||
if (tr_variantIsContainer(&node.v))
|
||||
{
|
||||
walkFuncs->containerEndFunc(&node.v, user_data);
|
||||
}
|
||||
v = node.nextChild();
|
||||
|
||||
stack.pop();
|
||||
continue;
|
||||
if (v != nullptr)
|
||||
{
|
||||
if (tr_variantIsDict(&node.v))
|
||||
{
|
||||
auto tmp = tr_variant{};
|
||||
tr_variantInitQuark(&tmp, v->key);
|
||||
walkFuncs->stringFunc(&tmp, user_data);
|
||||
}
|
||||
}
|
||||
else // finished with this node
|
||||
{
|
||||
if (tr_variantIsContainer(&node.v))
|
||||
{
|
||||
walkFuncs->containerEndFunc(&node.v, user_data);
|
||||
}
|
||||
|
||||
stack.pop();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (v != nullptr)
|
||||
|
|
|
@ -73,10 +73,8 @@ tr_watchdir_backend* tr_watchdir_generic_new(tr_watchdir_t handle)
|
|||
{
|
||||
auto* backend = new tr_watchdir_generic{};
|
||||
backend->base.free_func = &tr_watchdir_generic_free;
|
||||
|
||||
if ((backend
|
||||
->event = event_new(tr_watchdir_get_event_base(handle), -1, EV_PERSIST, &tr_watchdir_generic_on_event, handle)) ==
|
||||
nullptr)
|
||||
backend->event = event_new(tr_watchdir_get_event_base(handle), -1, EV_PERSIST, &tr_watchdir_generic_on_event, handle);
|
||||
if (backend->event == nullptr)
|
||||
{
|
||||
auto const error_code = errno;
|
||||
tr_logAddError(fmt::format(
|
||||
|
|
|
@ -99,7 +99,8 @@ static void tr_watchdir_inotify_on_event(struct bufferevent* event, void* contex
|
|||
}
|
||||
|
||||
/* Consume entire name into buffer */
|
||||
if ((nread = bufferevent_read(event, name, ev.len)) == (size_t)-1)
|
||||
nread = bufferevent_read(event, name, ev.len);
|
||||
if (nread == static_cast<size_t>(-1))
|
||||
{
|
||||
auto const error_code = errno;
|
||||
tr_logAddError(fmt::format(
|
||||
|
|
|
@ -61,5 +61,5 @@ void AboutDialog::showCredits()
|
|||
|
||||
void AboutDialog::showLicense()
|
||||
{
|
||||
Utils::openDialog(license_dialog_, this);
|
||||
Utils::openDialog(license_dialog_, this); // NOLINT clang-analyzer-cplusplus.NewDelete
|
||||
}
|
||||
|
|
|
@ -815,28 +815,27 @@ RpcResponseFuture Session::exec(std::string_view method, tr_variant* args)
|
|||
|
||||
void Session::updateStats(tr_variant* d, tr_session_stats* stats)
|
||||
{
|
||||
auto value = dictFind<uint64_t>(d, TR_KEY_uploadedBytes);
|
||||
if (value)
|
||||
if (auto const value = dictFind<uint64_t>(d, TR_KEY_uploadedBytes); value)
|
||||
{
|
||||
stats->uploadedBytes = *value;
|
||||
}
|
||||
|
||||
if ((value = dictFind<uint64_t>(d, TR_KEY_downloadedBytes)))
|
||||
if (auto const value = dictFind<uint64_t>(d, TR_KEY_downloadedBytes); value)
|
||||
{
|
||||
stats->downloadedBytes = *value;
|
||||
}
|
||||
|
||||
if ((value = dictFind<uint64_t>(d, TR_KEY_filesAdded)))
|
||||
if (auto const value = dictFind<uint64_t>(d, TR_KEY_filesAdded); value)
|
||||
{
|
||||
stats->filesAdded = *value;
|
||||
}
|
||||
|
||||
if ((value = dictFind<uint64_t>(d, TR_KEY_sessionCount)))
|
||||
if (auto const value = dictFind<uint64_t>(d, TR_KEY_sessionCount); value)
|
||||
{
|
||||
stats->sessionCount = *value;
|
||||
}
|
||||
|
||||
if ((value = dictFind<uint64_t>(d, TR_KEY_secondsActive)))
|
||||
if (auto const value = dictFind<uint64_t>(d, TR_KEY_secondsActive); value)
|
||||
{
|
||||
stats->secondsActive = *value;
|
||||
}
|
||||
|
|
|
@ -174,7 +174,6 @@ QString timeToStringRounded(int seconds)
|
|||
|
||||
QString TrackerDelegate::getText(TrackerInfo const& inf) const
|
||||
{
|
||||
QString key;
|
||||
QString str;
|
||||
auto const err_markup_begin = QStringLiteral("<span style=\"color:red\">");
|
||||
auto const err_markup_end = QStringLiteral("</span>");
|
||||
|
@ -198,11 +197,6 @@ QString TrackerDelegate::getText(TrackerInfo const& inf) const
|
|||
auto const url = QUrl(inf.st.announce);
|
||||
str += QStringLiteral("%1:%2").arg(url.host()).arg(url.port(80));
|
||||
|
||||
if (!key.isEmpty())
|
||||
{
|
||||
str += QStringLiteral(" - ") + key;
|
||||
}
|
||||
|
||||
str += inf.st.is_backup ? QStringLiteral("</i>") : QStringLiteral("</b>");
|
||||
|
||||
// announce & scrape info
|
||||
|
|
|
@ -63,7 +63,7 @@ public:
|
|||
{
|
||||
if (dialog.isNull())
|
||||
{
|
||||
dialog = new DialogT(std::forward<ArgsT>(args)...);
|
||||
dialog = new DialogT(std::forward<ArgsT>(args)...); // NOLINT clang-analyzer-cplusplus.NewDelete
|
||||
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||
dialog->show();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue