mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-14 16:04:03 +02:00
Replace hard-coded MiB byte conversions (e.g. `1024*1024`, `1<<20`, `1048576`) with the existing `_MiB` literal to improve readability and avoid repeating constants.
In the few spots where arithmetic involves signed values, the result is identical to the previous code assuming those quantities never turn negative.
Also switch to brace init on every declaration assigned from `_MiB`/`_GiB` literals so a future oversized value (e.g. `unsigned int x{4096_MiB}`) becomes a compile error through the C++11 narrowing check instead of silently truncating.
Extend unit tests to cover the 32-bit `size_t` overflow boundary and to assert equivalence for integer and floating-point conversions.
Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
Co-authored-by: w0xlt <94266259+w0xlt@users.noreply.github.com>
35 lines
1.1 KiB
C++
35 lines
1.1 KiB
C++
// Copyright (c) 2019-present The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <script/parsing.h>
|
|
#include <test/fuzz/FuzzedDataProvider.h>
|
|
#include <test/fuzz/fuzz.h>
|
|
#include <util/byte_units.h>
|
|
#include <util/string.h>
|
|
|
|
using util::Split;
|
|
|
|
FUZZ_TARGET(script_parsing)
|
|
{
|
|
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
|
const size_t query_size = fuzzed_data_provider.ConsumeIntegral<size_t>();
|
|
const std::string query = fuzzed_data_provider.ConsumeBytesAsString(std::min<size_t>(query_size, 1_MiB));
|
|
const std::string span_str = fuzzed_data_provider.ConsumeRemainingBytesAsString();
|
|
const std::span<const char> const_span{span_str};
|
|
|
|
std::span<const char> mut_span = const_span;
|
|
(void)script::Const(query, mut_span);
|
|
|
|
mut_span = const_span;
|
|
(void)script::Func(query, mut_span);
|
|
|
|
mut_span = const_span;
|
|
(void)script::Expr(mut_span);
|
|
|
|
if (!query.empty()) {
|
|
mut_span = const_span;
|
|
(void)Split(mut_span, query.front());
|
|
}
|
|
}
|