Skip to content

Commit f94f3e0

Browse files
committed
Avoid integer overflows in scriptnum tests
1 parent 843c560 commit f94f3e0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/test/scriptnum_tests.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212

1313
BOOST_FIXTURE_TEST_SUITE(scriptnum_tests, BasicTestingSetup)
1414

15-
static const int64_t values[] = \
16-
{ 0, 1, CHAR_MIN, CHAR_MAX, UCHAR_MAX, SHRT_MIN, USHRT_MAX, INT_MIN, INT_MAX, UINT_MAX, LONG_MIN, LONG_MAX };
15+
/** A selection of numbers that do not trigger int64_t overflow
16+
* when added/subtracted. */
17+
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 };
18+
1719
static const int64_t offsets[] = { 1, 0x79, 0x80, 0x81, 0xFF, 0x7FFF, 0x8000, 0xFFFF, 0x10000};
1820

1921
static bool verify(const CScriptNum10& bignum, const CScriptNum& scriptnum)

0 commit comments

Comments
 (0)