Skip to content

Commit 9217f9f

Browse files
author
MarcoFalke
committed
Merge #21522: fuzz: [refactor] Use PickValue where possible
fa818ca fuzz: [refactor] Use PickValue where possible (MarcoFalke) Pull request description: `PickValue` is a bit less typing, so I think it should be used where possible ACKs for top commit: practicalswift: cr ACK fa818ca: patch looks correct and `PickValue` is better :) Tree-SHA512: 49ed030694e3b7676654f1615f033287d26e2f0bc29647e1db56e0d84e14d29080f3e1898f5df8d644d834b8ded3ce713d2425ea86a37c9279d01f86ad03c202
2 parents 8f94c70 + fa818ca commit 9217f9f

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/test/fuzz/pow.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ FUZZ_TARGET_INIT(pow, initialize_pow)
3434
}
3535
CBlockIndex current_block{*block_header};
3636
{
37-
CBlockIndex* previous_block = !blocks.empty() ? &blocks[fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, blocks.size() - 1)] : nullptr;
37+
CBlockIndex* previous_block = blocks.empty() ? nullptr : &PickValue(fuzzed_data_provider, blocks);
3838
const int current_height = (previous_block != nullptr && previous_block->nHeight != std::numeric_limits<int>::max()) ? previous_block->nHeight + 1 : 0;
3939
if (fuzzed_data_provider.ConsumeBool()) {
4040
current_block.pprev = previous_block;
@@ -66,9 +66,9 @@ FUZZ_TARGET_INIT(pow, initialize_pow)
6666
}
6767
}
6868
{
69-
const CBlockIndex* to = &blocks[fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, blocks.size() - 1)];
70-
const CBlockIndex* from = &blocks[fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, blocks.size() - 1)];
71-
const CBlockIndex* tip = &blocks[fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, blocks.size() - 1)];
69+
const CBlockIndex* to = &PickValue(fuzzed_data_provider, blocks);
70+
const CBlockIndex* from = &PickValue(fuzzed_data_provider, blocks);
71+
const CBlockIndex* tip = &PickValue(fuzzed_data_provider, blocks);
7272
try {
7373
(void)GetBlockProofEquivalentTime(*to, *from, *tip, consensus_params);
7474
} catch (const uint_error&) {

src/test/fuzz/process_messages.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ FUZZ_TARGET_INIT(process_messages, initialize_process_messages)
6565
net_msg.m_type = random_message_type;
6666
net_msg.data = ConsumeRandomLengthByteVector(fuzzed_data_provider);
6767

68-
CNode& random_node = *peers.at(fuzzed_data_provider.ConsumeIntegralInRange<int>(0, peers.size() - 1));
68+
CNode& random_node = *PickValue(fuzzed_data_provider, peers);
6969

7070
(void)connman.ReceiveMsgFrom(random_node, net_msg);
7171
random_node.fPauseSend = false;

src/test/fuzz/util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void CallOneOf(FuzzedDataProvider& fuzzed_data_provider, Callables... callables)
4949
}
5050

5151
template <typename Collection>
52-
const auto& PickValue(FuzzedDataProvider& fuzzed_data_provider, const Collection& col)
52+
auto& PickValue(FuzzedDataProvider& fuzzed_data_provider, Collection& col)
5353
{
5454
const auto sz = col.size();
5555
assert(sz >= 1);

0 commit comments

Comments
 (0)