mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-18 22:35:39 +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
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user