aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpracticalswift <practicalswift@users.noreply.github.com>2020-06-11 12:41:39 +0000
committerpracticalswift <practicalswift@users.noreply.github.com>2020-06-11 14:05:54 +0000
commit4a8181b303218683d014e8e79a172ea8ccccc4dd (patch)
treed15bde10ffdfd64b662b06f15f76d07250168358 /src
parent45a6811d36fc59ce0d7e2be7a848059a05b0486e (diff)
downloadbitcoin-4a8181b303218683d014e8e79a172ea8ccccc4dd.tar.xz
tests: Add std::vector<uint8_t> ConsumeFixedLengthByteVector(FuzzedDataProvider& fuzzed_data_provider, const size_t length)
Diffstat (limited to 'src')
-rw-r--r--src/test/fuzz/util.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/test/fuzz/util.h b/src/test/fuzz/util.h
index f26878a704..1c1b2cd254 100644
--- a/src/test/fuzz/util.h
+++ b/src/test/fuzz/util.h
@@ -214,4 +214,18 @@ NODISCARD inline bool ContainsSpentInput(const CTransaction& tx, const CCoinsVie
return false;
}
+/**
+ * Returns a byte vector of specified size regardless of the number of remaining bytes available
+ * from the fuzzer. Pads with zero value bytes if needed to achieve the specified size.
+ */
+NODISCARD inline std::vector<uint8_t> ConsumeFixedLengthByteVector(FuzzedDataProvider& fuzzed_data_provider, const size_t length) noexcept
+{
+ std::vector<uint8_t> result(length);
+ const std::vector<uint8_t> random_bytes = fuzzed_data_provider.ConsumeBytes<uint8_t>(length);
+ if (!random_bytes.empty()) {
+ std::memcpy(result.data(), random_bytes.data(), random_bytes.size());
+ }
+ return result;
+}
+
#endif // BITCOIN_TEST_FUZZ_UTIL_H