aboutsummaryrefslogtreecommitdiff
path: root/src/bignum.h
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2012-06-18 10:48:40 -0400
committerGavin Andresen <gavinandresen@gmail.com>2012-06-18 10:48:40 -0400
commit550c73f4c87825e8524f7f164e0bc3e80c6822b9 (patch)
treea674350fd0b5b4dd017ce5c553a268d960cbf287 /src/bignum.h
parent5204ca87e23fb94f31e733c63efcb46980ad42ad (diff)
parent31ac53fbdc2346876da201b9e1495565b38b46ba (diff)
Merge branch 'signbugs' of https://github.com/wizeman/bitcoin
Resolved minor conflict in main.cpp
Diffstat (limited to 'src/bignum.h')
-rw-r--r--src/bignum.h22
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++)
{