aboutsummaryrefslogtreecommitdiff
path: root/src/test/getarg_tests.cpp
diff options
context:
space:
mode:
authorJames O'Beirne <james.obeirne@pm.me>2021-12-22 12:11:13 -0500
committerRyan Ofsky <ryan@ofsky.org>2022-01-11 19:54:36 -0500
commitb5c9bb5cb9f4a8db57b33ef7399310c7d6de5822 (patch)
tree005cf7c5a83f7f72aca4c10664483bd4b4ae361a /src/test/getarg_tests.cpp
parentc561f2f06ed25f08f7776ac41aeb2999ebe79550 (diff)
downloadbitcoin-b5c9bb5cb9f4a8db57b33ef7399310c7d6de5822.tar.xz
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/getarg_tests.cpp')
-rw-r--r--src/test/getarg_tests.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/test/getarg_tests.cpp b/src/test/getarg_tests.cpp
index 88ce9648bc..d5142c8d74 100644
--- a/src/test/getarg_tests.cpp
+++ b/src/test/getarg_tests.cpp
@@ -6,6 +6,7 @@
#include <util/strencodings.h>
#include <util/system.h>
+#include <limits>
#include <string>
#include <utility>
#include <vector>
@@ -144,6 +145,11 @@ BOOST_AUTO_TEST_CASE(intarg)
BOOST_CHECK_EQUAL(m_local_args.GetIntArg("-foo", 11), 0);
BOOST_CHECK_EQUAL(m_local_args.GetIntArg("-bar", 11), 0);
+ // Check under-/overflow behavior.
+ ResetArgs("-foo=-9223372036854775809 -bar=9223372036854775808");
+ BOOST_CHECK_EQUAL(m_local_args.GetIntArg("-foo", 0), std::numeric_limits<int64_t>::min());
+ BOOST_CHECK_EQUAL(m_local_args.GetIntArg("-bar", 0), std::numeric_limits<int64_t>::max());
+
ResetArgs("-foo=11 -bar=12");
BOOST_CHECK_EQUAL(m_local_args.GetIntArg("-foo", 0), 11);
BOOST_CHECK_EQUAL(m_local_args.GetIntArg("-bar", 11), 12);