mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 06:43:45 +01:00
util: Restore GetIntArg saturating behavior
The new locale-independent atoi64 method introduced in #20452 parses large integer values higher than maximum representable value as 0 instead of the maximum value, which breaks backwards compatibility. This commit restores compatibility and adds test coverage for this case in terms of the related GetIntArg and strtoll functions. Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
This commit is contained in:
committed by
Ryan Ofsky
parent
c561f2f06e
commit
b5c9bb5cb9
@@ -276,20 +276,14 @@ FUZZ_TARGET(string)
|
||||
}
|
||||
|
||||
{
|
||||
const int atoi_result = atoi(random_string_1.c_str());
|
||||
const int locale_independent_atoi_result = LocaleIndependentAtoi<int>(random_string_1);
|
||||
const int64_t atoi64_result = atoi64_legacy(random_string_1);
|
||||
const bool out_of_range = atoi64_result < std::numeric_limits<int>::min() || atoi64_result > std::numeric_limits<int>::max();
|
||||
if (out_of_range) {
|
||||
assert(locale_independent_atoi_result == 0);
|
||||
} else {
|
||||
assert(atoi_result == locale_independent_atoi_result);
|
||||
}
|
||||
assert(locale_independent_atoi_result == std::clamp<int64_t>(atoi64_result, std::numeric_limits<int>::min(), std::numeric_limits<int>::max()));
|
||||
}
|
||||
|
||||
{
|
||||
const int64_t atoi64_result = atoi64_legacy(random_string_1);
|
||||
const int64_t locale_independent_atoi_result = LocaleIndependentAtoi<int64_t>(random_string_1);
|
||||
assert(atoi64_result == locale_independent_atoi_result || locale_independent_atoi_result == 0);
|
||||
assert(atoi64_result == locale_independent_atoi_result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user