diff options
author | Giel van Schijndel <me@mortis.eu> | 2012-06-24 12:34:15 +0200 |
---|---|---|
committer | Giel van Schijndel <me@mortis.eu> | 2012-06-24 12:34:15 +0200 |
commit | 415a87ef363396fe689ec452a30d36b1752eab2e (patch) | |
tree | 1f68453bf98ac1a4a94394e2792fd3175480cd52 /src/bignum.h | |
parent | 896899e0d66e25f6549a92749d237c8a87b12f08 (diff) | |
parent | 817ee0d826087d418b5f0bffcdd92429574284e2 (diff) |
Merge branch 'master' into async-ipv6-rpc
Diffstat (limited to 'src/bignum.h')
-rw-r--r-- | src/bignum.h | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/bignum.h b/src/bignum.h index 307017b0ab..9af934051a 100644 --- a/src/bignum.h +++ b/src/bignum.h @@ -122,16 +122,30 @@ public: return (n > (unsigned long)std::numeric_limits<int>::max() ? std::numeric_limits<int>::min() : -(int)n); } - void setint64(int64 n) + void setint64(int64 sn) { - unsigned char pch[sizeof(n) + 6]; + unsigned char pch[sizeof(sn) + 6]; unsigned char* p = pch + 4; - bool fNegative = false; - if (n < (int64)0) + bool fNegative; + uint64 n; + + if (sn < (int64)0) { + // 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; + } else { + n = sn; + fNegative = false; } + bool fLeadingZeroes = true; for (int i = 0; i < 8; i++) { |