From 7e8ef959d0637ca5543ed33d3919937e0d053e70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc?= Date: Mon, 28 Apr 2025 16:08:51 +0200 Subject: [PATCH] refactor: Fix Sonar rule `cpp:S4998` - avoid unique_ptr const& as parameter Changed `FindChallenges()` parameter from `const std::unique_ptr>&` to const `Node*`. Sonar rule `cpp:S4998` - https://sonarcloud.io/project/issues?issueStatuses=OPEN%2CCONFIRMED&branch=32351-8c0e673c4ac31c1c04750756de749fb813b2c33f&id=aureleoules_bitcoin&open=AZZ2q88IvFhp-eMuMy96: > Replace this use of "unique_ptr" by a raw pointer or a reference (possibly const). > Function parameters should not be of type "std::unique_ptr const &" cpp:S4998 > Software qualities impacted: Maintainability --- src/test/miniscript_tests.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/miniscript_tests.cpp b/src/test/miniscript_tests.cpp index a3d8d4ed5d7..0a32727f37e 100644 --- a/src/test/miniscript_tests.cpp +++ b/src/test/miniscript_tests.cpp @@ -297,12 +297,12 @@ using miniscript::operator""_mst; using Node = miniscript::Node; /** Compute all challenges (pubkeys, hashes, timelocks) that occur in a given Miniscript. */ -std::set FindChallenges(const NodeRef& root) +std::set FindChallenges(const Node* root) { std::set chal; - for (std::vector stack{root.get()}; !stack.empty();) { - const Node* ref{stack.back()}; + for (std::vector stack{root}; !stack.empty();) { + const auto* ref{stack.back()}; stack.pop_back(); for (const auto& key : ref->keys) { @@ -348,7 +348,7 @@ struct MiniScriptTest : BasicTestingSetup { /** Run random satisfaction tests. */ void TestSatisfy(const KeyConverter& converter, const std::string& testcase, const NodeRef& node) { auto script = node->ToScript(converter); - const auto challenges{FindChallenges(node)}; // Find all challenges in the generated miniscript. + const auto challenges{FindChallenges(node.get())}; // Find all challenges in the generated miniscript. std::vector challist(challenges.begin(), challenges.end()); for (int iter = 0; iter < 3; ++iter) { std::shuffle(challist.begin(), challist.end(), m_rng);