aboutsummaryrefslogtreecommitdiff
path: root/src/test/scriptnum_tests.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2017-01-10 14:34:20 -0800
committerPieter Wuille <pieter.wuille@gmail.com>2017-01-12 11:52:53 -0800
commitf94f3e0df82cd9f1202b0741c6fcc83b3560cee8 (patch)
tree23be03c47403807c7cfb58d1f167f5aab323cbcb /src/test/scriptnum_tests.cpp
parent843c560003b288a073f528ef16b83541f7a9b0ac (diff)
Avoid integer overflows in scriptnum tests
Diffstat (limited to 'src/test/scriptnum_tests.cpp')
-rw-r--r--src/test/scriptnum_tests.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/test/scriptnum_tests.cpp b/src/test/scriptnum_tests.cpp
index 6b6689c7d3..1d5893bdc3 100644
--- a/src/test/scriptnum_tests.cpp
+++ b/src/test/scriptnum_tests.cpp
@@ -12,8 +12,10 @@
BOOST_FIXTURE_TEST_SUITE(scriptnum_tests, BasicTestingSetup)
-static const int64_t values[] = \
-{ 0, 1, CHAR_MIN, CHAR_MAX, UCHAR_MAX, SHRT_MIN, USHRT_MAX, INT_MIN, INT_MAX, UINT_MAX, LONG_MIN, LONG_MAX };
+/** A selection of numbers that do not trigger int64_t overflow
+ * when added/subtracted. */
+static const int64_t values[] = { 0, 1, -2, 127, 128, -255, 256, (1LL << 15) - 1, -(1LL << 16), (1LL << 24) - 1, (1LL << 31), 1 - (1LL << 32), 1LL << 40 };
+
static const int64_t offsets[] = { 1, 0x79, 0x80, 0x81, 0xFF, 0x7FFF, 0x8000, 0xFFFF, 0x10000};
static bool verify(const CScriptNum10& bignum, const CScriptNum& scriptnum)