mirror of
https://github.com/dashpay/dash.git
synced 2024-12-30 22:35:51 +01:00
Fix signed subtraction overflow in CBigNum::setint64().
As noticed by sipa (Pieter Wuille), this can happen when CBigNum::setint64() is called with an integer value of INT64_MIN (-2^63). When compiled with -ftrapv, the program would crash. Otherwise, it would execute an undefined operation (although in practice, usually the correct one).
This commit is contained in:
parent
62e0453ce0
commit
5849bd472a
10
src/bignum.h
10
src/bignum.h
@ -131,7 +131,15 @@ public:
|
|||||||
|
|
||||||
if (sn < (int64)0)
|
if (sn < (int64)0)
|
||||||
{
|
{
|
||||||
n = -sn;
|
// We negate in 2 steps to avoid signed subtraction overflow,
|
||||||
|
// i.e. -(-2^63), which is an undefined operation and causes SIGILL
|
||||||
|
// when compiled with -ftrapv.
|
||||||
|
//
|
||||||
|
// Note that uint64_t n = sn, when sn is an int64_t, is a
|
||||||
|
// well-defined operation and n will be equal to sn + 2^64 when sn
|
||||||
|
// is negative.
|
||||||
|
n = sn;
|
||||||
|
n = -n;
|
||||||
fNegative = true;
|
fNegative = true;
|
||||||
} else {
|
} else {
|
||||||
n = sn;
|
n = sn;
|
||||||
|
Loading…
Reference in New Issue
Block a user