diff --git a/src/test/fuzz/txorphan.cpp b/src/test/fuzz/txorphan.cpp index 5129c05a397..31af1afff52 100644 --- a/src/test/fuzz/txorphan.cpp +++ b/src/test/fuzz/txorphan.cpp @@ -38,6 +38,7 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage) TxOrphanage orphanage; std::vector outpoints; // Duplicates are tolerated + outpoints.reserve(200'000); // initial outpoints used to construct transactions later for (uint8_t i = 0; i < 4; i++) { @@ -55,12 +56,14 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage) const auto num_out = fuzzed_data_provider.ConsumeIntegralInRange(1, 256); // pick outpoints from outpoints as input. We allow input duplicates on purpose, given we are not // running any transaction validation logic before adding transactions to the orphanage + tx_mut.vin.reserve(num_in); for (uint32_t i = 0; i < num_in; i++) { auto& prevout = PickValue(fuzzed_data_provider, outpoints); // try making transactions unique by setting a random nSequence, but allow duplicate transactions if they happen tx_mut.vin.emplace_back(prevout, CScript{}, fuzzed_data_provider.ConsumeIntegralInRange(0, CTxIn::SEQUENCE_FINAL)); } // output amount will not affect txorphanage + tx_mut.vout.reserve(num_out); for (uint32_t i = 0; i < num_out; i++) { tx_mut.vout.emplace_back(CAmount{0}, CScript{}); } diff --git a/src/test/fuzz/util.h b/src/test/fuzz/util.h index 8e2b8639c28..38be59fb64b 100644 --- a/src/test/fuzz/util.h +++ b/src/test/fuzz/util.h @@ -79,6 +79,7 @@ template { const size_t n_elements = fuzzed_data_provider.ConsumeIntegralInRange(0, max_vector_size); std::vector r; + r.reserve(n_elements); for (size_t i = 0; i < n_elements; ++i) { r.push_back(fuzzed_data_provider.ConsumeRandomLengthString(max_string_length)); } @@ -90,6 +91,7 @@ template { const size_t n_elements = fuzzed_data_provider.ConsumeIntegralInRange(0, max_vector_size); std::vector r; + r.reserve(n_elements); for (size_t i = 0; i < n_elements; ++i) { r.push_back(fuzzed_data_provider.ConsumeIntegral()); }