What changed, and why it matters
This commit is a simple code cleanup inside a fuzz test file. It pulls out a repeated block of code into a helper function named ConsumeDBParams() so it can be reused later. The commit message explicitly calls it a 'pure refactor with no behavior change,' and the diff only moves existing logic around without changing any values, checks, or program behavior.
No security action needed. This is a non-functional test-only refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change refactors src/test/fuzz/dbwrapper.cpp by extracting inline DBParams construction from TestDbWrapper’s make_db lambda into a new standalone ConsumeDBParams() helper. The helper takes the same FuzzedDataProvider, testing_env, obfuscate flag, and optional DBOptions, and returns the same DBParams struct with identical field assignments. No logic, ranges, defaults, or call sites outside the fuzz harness are modified.
Changed components
src/test/fuzz/dbwrapper.cppInspect captured patch +17 / −10
diff --git a/src/test/fuzz/dbwrapper.cpp b/src/test/fuzz/dbwrapper.cpp
index 13fff136..31ada986 100644
--- a/src/test/fuzz/dbwrapper.cpp
+++ b/src/test/fuzz/dbwrapper.cpp
@@ -152,6 +152,22 @@ void VerifyIterator(CDBWrapper& dbw, const Oracle& oracle,
assert(oracle_it == oracle.end());
}
+/** Build randomized DBParams from the fuzz input, shared by all targets. */
+DBParams ConsumeDBParams(FuzzedDataProvider& provider, leveldb::Env* testing_env,
+ bool obfuscate, DBOptions options = {})
+{
+ return DBParams{
+ .path = "dbwrapper_fuzz",
+ .cache_bytes = provider.ConsumeIntegralInRange<size_t>(64 << 10, 1_MiB),
+ .obfuscate = obfuscate,
+ .options = options,
+ .testing_env = testing_env,
+ .max_file_size = provider.ConsumeBool()
+ ? DBWRAPPER_MAX_FILE_SIZE
+ : provider.ConsumeIntegralInRange<size_t>(1_MiB, 4_MiB),
+ };
+}
+
template <typename DrainWorkFn, typename RunOneFn>
void TestDbWrapper(FuzzedDataProvider& provider,
leveldb::Env* testing_env,
@@ -164,16 +180,7 @@ void TestDbWrapper(FuzzedDataProvider& provider,
const bool obfuscate{provider.ConsumeBool()};
const auto make_db{[&](DBOptions options = {}) {
- return std::make_unique<CDBWrapper>(DBParams{
- .path = "dbwrapper_fuzz",
- .cache_bytes = provider.ConsumeIntegralInRange<size_t>(64 << 10, 1_MiB),
- .obfuscate = obfuscate,
- .options = options,
- .testing_env = testing_env,
- .max_file_size = provider.ConsumeBool()
- ? DBWRAPPER_MAX_FILE_SIZE
- : provider.ConsumeIntegralInRange<size_t>(1_MiB, 4_MiB),
- });
+ return std::make_unique<CDBWrapper>(ConsumeDBParams(provider, testing_env, obfuscate, options));
}};
std::unique_ptr<CDBWrapper> dbw{make_db()};
Why this scored 15/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.