aboutsummaryrefslogtreecommitdiff
path: root/src/util.cpp
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:37 -0400
commitc43a9ea77db06b9d101f0551df373d417e5028af (patch)
treee9d39713b8a652749c70ce1df1e00c00943da2f3 /src/util.cpp
parent810427470113ab25724a6f50abdcdf63118e683b (diff)
downloadbitcoin-c43a9ea77db06b9d101f0551df373d417e5028af.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/util.cpp')
-rw-r--r--src/util.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/util.cpp b/src/util.cpp
index b6b4ee645a..039c482f71 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -411,7 +411,7 @@ bool ParseMoney(const char* pszIn, int64& nRet)
}
-static char phexdigit[256] =
+static signed char phexdigit[256] =
{ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
@@ -447,12 +447,12 @@ vector<unsigned char> ParseHex(const char* psz)
{
while (isspace(*psz))
psz++;
- char c = phexdigit[(unsigned char)*psz++];
- if (c == (char)-1)
+ signed char c = phexdigit[(unsigned char)*psz++];
+ if (c == (signed char)-1)
break;
unsigned char n = (c << 4);
c = phexdigit[(unsigned char)*psz++];
- if (c == (char)-1)
+ if (c == (signed char)-1)
break;
n |= c;
vch.push_back(n);