diff options
author | James O'Beirne <james.obeirne@pm.me> | 2021-12-22 12:11:13 -0500 |
---|---|---|
committer | Ryan Ofsky <ryan@ofsky.org> | 2022-01-11 19:54:36 -0500 |
commit | b5c9bb5cb9f4a8db57b33ef7399310c7d6de5822 (patch) | |
tree | 005cf7c5a83f7f72aca4c10664483bd4b4ae361a /src/test/fuzz/string.cpp | |
parent | c561f2f06ed25f08f7776ac41aeb2999ebe79550 (diff) |
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>
Diffstat (limited to 'src/test/fuzz/string.cpp')
-rw-r--r-- | src/test/fuzz/string.cpp | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/src/test/fuzz/string.cpp b/src/test/fuzz/string.cpp index ab646c68fc..8f071b71fe 100644 --- a/src/test/fuzz/string.cpp +++ b/src/test/fuzz/string.cpp @@ -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); } } |