aboutsummaryrefslogtreecommitdiff
path: root/src/bignum.h
diff options
context:
space:
mode:
authorDwayne C. Litzenberger <dlitz@dlitz.net>2012-04-16 01:32:55 -0400
committerLuke Dashjr <luke-jr+git@utopios.org>2012-04-22 09:38:27 -0400
commite5b980d72f808c46ea279d1fa5bfc1f8fb3363c3 (patch)
tree591bc2f6588a85e659871ab5ff072961381fc80b /src/bignum.h
parentbd043f19c83654331e5418ea1e7af2bd213899a7 (diff)
downloadbitcoin-e5b980d72f808c46ea279d1fa5bfc1f8fb3363c3.tar.xz
Fix bugs on 'unsigned char' platforms.
In ISO C++, the signedness of 'char' is undefined. On some platforms (e.g. ARM), 'char' is an unsigned type, but some of the code relies on 'char' being signed (as it is on x86). This is indicated by compiler warnings like this: bignum.h: In constructor 'CBigNum::CBigNum(char)': bignum.h:81:59: warning: comparison is always true due to limited range of data type [-Wtype-limits] util.cpp: In function 'bool IsHex(const string&)': util.cpp:427:28: warning: comparison is always false due to limited range of data type [-Wtype-limits] In particular, IsHex erroneously returned true regardless of the input characters, as long as the length of the string was a positive multiple of 2. Note: For testing, it's possible using GCC to force char to be unsigned by adding the -funsigned-char parameter to xCXXFLAGS.
Diffstat (limited to 'src/bignum.h')
-rw-r--r--src/bignum.h5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/bignum.h b/src/bignum.h
index 641ebf4b05..fd5364e810 100644
--- a/src/bignum.h
+++ b/src/bignum.h
@@ -77,7 +77,8 @@ public:
BN_clear_free(this);
}
- CBigNum(char n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
+ //CBigNum(char n) is not portable. Use 'signed char' or 'unsigned char'.
+ CBigNum(signed char n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
CBigNum(short n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
CBigNum(int n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
CBigNum(long n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); }
@@ -295,7 +296,7 @@ public:
psz++;
// hex string to bignum
- static char phexdigit[256] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0, 0,0xa,0xb,0xc,0xd,0xe,0xf,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0xa,0xb,0xc,0xd,0xe,0xf,0,0,0,0,0,0,0,0,0 };
+ static signed char phexdigit[256] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0, 0,0xa,0xb,0xc,0xd,0xe,0xf,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0xa,0xb,0xc,0xd,0xe,0xf,0,0,0,0,0,0,0,0,0 };
*this = 0;
while (isxdigit(*psz))
{