Merge bitcoin/bitcoin#36588: refactor: Enable more tidy bugprone checks
What changed, and why it matters
This commit turns on additional automated code-quality checks in Bitcoin Core's clang-tidy configuration and makes a handful of small, matching cleanups. It is a refactoring/tooling change, not a fix for an active security bug. The only runtime code changes are switching one Qt container erase call to a safer modern form and adding a lifetime annotation to a D-Bus operator. The rest are test-only adjustments to satisfy new static-analysis rules.
No security response required. Treat as normal refactoring/CI tooling update. Reviewers may verify that the newly enabled clang-tidy checks pass in CI and that the small runtime cleanups are correct.
Security signals we found
Static-analysis hardening only
No vulnerability class fixed in consensus/network/runtime path
Vendor states checks found nothing severe
One erase-call cleanup is a defensive correctness improvement, not an exploitable bug fix
LIFETIMEBOUND annotation is documentation/tooling enforcement, not a runtime change
Evidence from the diff
The merge enables a set of clang-tidy ‘bugprone-*’ checks in src/.clang-tidy (dangling-handle, inaccurate-erase, lambda-function-name, nondeterministic-pointer-iteration-order, raw-memory-call-on-non-trivial-type, return-const-ref-from-parameter, spuriously-wake-up-functions, string-literal-with-embedded-nul, stringview-nullptr, suspicious-memory-comparison, swapped-arguments, undefined-memory-manipulation, unused-raii, virtual-near-miss, etc.). To satisfy the new checks, the diff: (1) replaces a std::remove/erase idiom with std::erase in WalletController::removeAndDeleteWallet, (2) adds a LIFETIMEBOUND attribute to a QDBusArgument extraction operator parameter, (3) marks a NotNull test variable as [[maybe_unused]], and (4) changes test string literals containing embedded NULs to std::string_view or std::string literals so the string-literal-with-embedded-nul check is not triggered. The PR description explicitly states the checks ‘didn’t find anything severe’ apart from a test-only bug.
Changed components
src/.clang-tidysrc/qt/notificator.cppsrc/qt/walletcontroller.cppsrc/test/util_not_null_tests.cppsrc/test/util_tests.cppInspect captured patch +24 / −9
### src/.clang-tidy
@@ -2,12 +2,25 @@ Checks: '
-*,
bitcoin-*,
bugprone-argument-comment,
+bugprone-dangling-handle,
+bugprone-inaccurate-erase,
+bugprone-lambda-function-name,
bugprone-move-forwarding-reference,
+bugprone-nondeterministic-pointer-iteration-order,
+bugprone-raw-memory-call-on-non-trivial-type,
+bugprone-return-const-ref-from-parameter,
+bugprone-spuriously-wake-up-functions,
bugprone-string-constructor,
-bugprone-use-after-move,
-bugprone-lambda-function-name,
+bugprone-string-literal-with-embedded-nul,
+bugprone-stringview-nullptr,
+bugprone-suspicious-memory-comparison,
+bugprone-swapped-arguments,
+bugprone-undefined-memory-manipulation,
bugprone-unhandled-self-assignment,
+bugprone-unused-raii,
bugprone-unused-return-value,
+bugprone-use-after-move,
+bugprone-virtual-near-miss,
fuchsia-header-anon-namespaces,
misc-definitions-in-headers,
misc-no-recursion,
### src/qt/notificator.cpp
@@ -6,6 +6,8 @@
#include <qt/notificator.h>
+#include <attributes.h>
+
#include <QApplication>
#include <QByteArray>
#include <QImageWriter>
@@ -82,8 +84,8 @@ class FreedesktopImage
int bitsPerSample;
QByteArray image;
- friend QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopImage &i);
- friend const QDBusArgument &operator>>(const QDBusArgument &a, FreedesktopImage &i);
+ friend QDBusArgument& operator<<(QDBusArgument& a, const FreedesktopImage& i);
+ friend const QDBusArgument& operator>>(const QDBusArgument& a LIFETIMEBOUND, FreedesktopImage& i);
};
Q_DECLARE_METATYPE(FreedesktopImage);
### src/qt/walletcontroller.cpp
@@ -179,7 +179,7 @@ void WalletController::removeAndDeleteWallet(WalletModel* wallet_model)
// Unregister wallet model.
{
QMutexLocker locker(&m_mutex);
- m_wallets.erase(std::remove(m_wallets.begin(), m_wallets.end(), wallet_model));
+ std::erase(m_wallets, wallet_model);
}
Q_EMIT walletRemoved(wallet_model);
// Currently this can trigger the unload since the model can hold the last
### src/test/util_not_null_tests.cpp
@@ -88,7 +88,7 @@ template <class Target, class Source>
concept NotNullCopyConvertible = requires {
typename std::bool_constant<([] {
util::NotNull<Source> copy_source{Source{}};
- util::NotNull<Target>{copy_source};
+ [[maybe_unused]] util::NotNull<Target> copy_target{copy_source};
return true;
}())>;
};
### src/test/util_tests.cpp
@@ -1153,7 +1153,7 @@ BOOST_AUTO_TEST_CASE(test_ToLower)
BOOST_CHECK_EQUAL(ToLower(""), "");
BOOST_CHECK_EQUAL(ToLower("#HODL"), "#hodl");
- BOOST_CHECK_EQUAL(ToLower("\x00\xfe\xff"), "\x00\xfe\xff");
+ BOOST_CHECK_EQUAL(ToLower("\x00\xfe\xff"sv), "\x00\xfe\xff"sv);
}
BOOST_AUTO_TEST_CASE(test_ToUpper)
@@ -1167,14 +1167,14 @@ BOOST_AUTO_TEST_CASE(test_ToUpper)
BOOST_CHECK_EQUAL(ToUpper(""), "");
BOOST_CHECK_EQUAL(ToUpper("#hodl"), "#HODL");
- BOOST_CHECK_EQUAL(ToUpper("\x00\xfe\xff"), "\x00\xfe\xff");
+ BOOST_CHECK_EQUAL(ToUpper("\x00\xfe\xff"sv), "\x00\xfe\xff"sv);
}
BOOST_AUTO_TEST_CASE(test_Capitalize)
{
BOOST_CHECK_EQUAL(Capitalize(""), "");
BOOST_CHECK_EQUAL(Capitalize("bitcoin"), "Bitcoin");
- BOOST_CHECK_EQUAL(Capitalize("\x00\xfe\xff"), "\x00\xfe\xff");
+ BOOST_CHECK_EQUAL(Capitalize("\x00\xfe\xff"s), "\x00\xfe\xff"sv);
}
static std::string SpanToStr(const std::span<const char>& span)Why this scored 18/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.