nit: could be more consistent by not using a global for one and a default param for the other:
(note: these diffs do not include the return true comment made further down)
<details>
<summary>git diff on 0d961c1d97</summary>
diff --git a/src/test/fuzz/util/descriptor.cpp b/src/test/fuzz/util/descriptor.cpp
index c2aa6d9b6a..804fd1cd33 100644
--- a/src/test/fuzz/util/descriptor.cpp
+++ b/src/test/fuzz/util/descriptor.cpp
@@ -87,16 +87,13 @@ bool HasDeepDerivPath(const FuzzBufferType& buff, const int max_depth)
return false;
}
-//! Maximum number of nested sub-fragments we'll allow in a descriptor.
-constexpr int MAX_NESTED_SUBS{10'000};
-
-bool HasTooManySubFrag(const FuzzBufferType& buff, const int max_subs)
+bool HasTooManySubFrag(const FuzzBufferType& buff, const int max_subs, const int max_nested_subs)
{
// We use a stack because there may be many nested sub-frags.
std::stack<int> counts;
for (const auto& ch: buff) {
// The fuzzer may generate an input with a ton of parenthesis. Rule out pathological cases.
- if (counts.size() > MAX_NESTED_SUBS) return false;
+ if (counts.size() > max_nested_subs) return false;
if (ch == '(') {
// A new fragment was opened, create a new sub-count for it and start as one since any fragment with
diff --git a/src/test/fuzz/util/descriptor.h b/src/test/fuzz/util/descriptor.h
index 77ebd11ebb..22205d41ab 100644
--- a/src/test/fuzz/util/descriptor.h
+++ b/src/test/fuzz/util/descriptor.h
@@ -57,11 +57,14 @@ bool HasDeepDerivPath(const FuzzBufferType& buff, const int max_depth = MAX_DEPT
//! Default maximum number of sub-fragments.
constexpr int MAX_SUBS{1'000};
+//! Maximum number of nested sub-fragments we'll allow in a descriptor.
+constexpr int MAX_NESTED_SUBS{10'000};
/**
* Whether the buffer, if it represents a valid descriptor, contains a fragment with more
* sub-fragments than the given maximum.
*/
-bool HasTooManySubFrag(const FuzzBufferType& buff, const int max_subs = MAX_SUBS);
+bool HasTooManySubFrag(const FuzzBufferType& buff, const int max_subs = MAX_SUBS,
+ const int max_nested_subs = MAX_NESTED_SUBS);
#endif // BITCOIN_TEST_FUZZ_UTIL_DESCRIPTOR_H
</details>
Also, this raises a narrowing warning:
CXX test/fuzz/util/libtest_fuzz_a-descriptor.o
test/fuzz/util/descriptor.cpp:96:27: warning: comparison of integers of different signs: 'std::stack<int>::size_type' (aka 'unsigned long') and 'const int' [-Wsign-compare]
if (counts.size() > max_nested_subs) return false;
~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~
1 warning generated.
So using size_t for the max values might make sense?
<details>
<summary>git diff on 0d961c1d97</summary>
diff --git a/src/test/fuzz/util/descriptor.cpp b/src/test/fuzz/util/descriptor.cpp
index c2aa6d9b6a..e3b5218e15 100644
--- a/src/test/fuzz/util/descriptor.cpp
+++ b/src/test/fuzz/util/descriptor.cpp
@@ -87,16 +87,14 @@ bool HasDeepDerivPath(const FuzzBufferType& buff, const int max_depth)
return false;
}
-//! Maximum number of nested sub-fragments we'll allow in a descriptor.
-constexpr int MAX_NESTED_SUBS{10'000};
-
-bool HasTooManySubFrag(const FuzzBufferType& buff, const int max_subs)
+bool HasTooManySubFrag(const FuzzBufferType& buff, const size_t max_subs,
+ const size_t max_nested_subs)
{
// We use a stack because there may be many nested sub-frags.
- std::stack<int> counts;
+ std::stack<size_t> counts;
for (const auto& ch: buff) {
// The fuzzer may generate an input with a ton of parenthesis. Rule out pathological cases.
- if (counts.size() > MAX_NESTED_SUBS) return false;
+ if (counts.size() > max_nested_subs) return false;
if (ch == '(') {
// A new fragment was opened, create a new sub-count for it and start as one since any fragment with
diff --git a/src/test/fuzz/util/descriptor.h b/src/test/fuzz/util/descriptor.h
index 77ebd11ebb..a379883be8 100644
--- a/src/test/fuzz/util/descriptor.h
+++ b/src/test/fuzz/util/descriptor.h
@@ -56,12 +56,15 @@ constexpr int MAX_DEPTH{2};
bool HasDeepDerivPath(const FuzzBufferType& buff, const int max_depth = MAX_DEPTH);
//! Default maximum number of sub-fragments.
-constexpr int MAX_SUBS{1'000};
+constexpr size_t MAX_SUBS{1'000};
+//! Maximum number of nested sub-fragments we'll allow in a descriptor.
+constexpr size_t MAX_NESTED_SUBS{10'000};
/**
* Whether the buffer, if it represents a valid descriptor, contains a fragment with more
* sub-fragments than the given maximum.
*/
-bool HasTooManySubFrag(const FuzzBufferType& buff, const int max_subs = MAX_SUBS);
+bool HasTooManySubFrag(const FuzzBufferType& buff, const size_t max_subs = MAX_SUBS,
+ const size_t max_nested_subs = MAX_NESTED_SUBS);
#endif // BITCOIN_TEST_FUZZ_UTIL_DESCRIPTOR_H
</details>