Browse Source

Add casts for unavoidable signed/unsigned comparisons

At these code sites, it is preferable to cast rather than change
a variable's type.
0.8
Jeff Garzik 13 years ago committed by Jeff Garzik
parent
commit
1d8c7a9557
  1. 4
      src/bignum.h
  2. 10
      src/bitcoinrpc.cpp
  3. 10
      src/main.cpp
  4. 2
      src/main.h
  5. 2
      src/protocol.cpp
  6. 8
      src/script.cpp
  7. 2
      src/script.h
  8. 2
      src/util.cpp

4
src/bignum.h

@ -117,9 +117,9 @@ public:
{ {
unsigned long n = BN_get_word(this); unsigned long n = BN_get_word(this);
if (!BN_is_negative(this)) if (!BN_is_negative(this))
return (n > std::numeric_limits<int>::max() ? std::numeric_limits<int>::max() : n); return (n > (unsigned long)std::numeric_limits<int>::max() ? std::numeric_limits<int>::max() : n);
else else
return (n > std::numeric_limits<int>::max() ? std::numeric_limits<int>::min() : -(int)n); return (n > (unsigned long)std::numeric_limits<int>::max() ? std::numeric_limits<int>::min() : -(int)n);
} }
void setint64(int64 n) void setint64(int64 n)

10
src/bitcoinrpc.cpp

@ -999,7 +999,7 @@ Value addmultisigaddress(const Array& params, bool fHelp)
strAccount = AccountFromValue(params[2]); strAccount = AccountFromValue(params[2]);
// Gather public keys // Gather public keys
if (nRequired < 1 || keys.size() < nRequired) if ((nRequired < 1) || ((int)keys.size() < nRequired))
throw runtime_error( throw runtime_error(
strprintf("wrong number of keys" strprintf("wrong number of keys"
"(got %d, need at least %d)", keys.size(), nRequired)); "(got %d, need at least %d)", keys.size(), nRequired));
@ -1331,8 +1331,10 @@ Value listtransactions(const Array& params, bool fHelp)
} }
// ret is newest to oldest // ret is newest to oldest
if (nFrom > ret.size()) nFrom = ret.size(); if (nFrom > (int)ret.size())
if (nFrom+nCount > ret.size()) nCount = ret.size()-nFrom; nFrom = ret.size();
if ((nFrom + nCount) > (int)ret.size())
nCount = ret.size() - nFrom;
Array::iterator first = ret.begin(); Array::iterator first = ret.begin();
std::advance(first, nFrom); std::advance(first, nFrom);
Array::iterator last = ret.begin(); Array::iterator last = ret.begin();
@ -2202,7 +2204,7 @@ int ReadHTTP(std::basic_istream<char>& stream, map<string, string>& mapHeadersRe
// Read header // Read header
int nLen = ReadHTTPHeader(stream, mapHeadersRet); int nLen = ReadHTTPHeader(stream, mapHeadersRet);
if (nLen < 0 || nLen > MAX_SIZE) if (nLen < 0 || nLen > (int)MAX_SIZE)
return 500; return 500;
// Read message // Read message

10
src/main.cpp

@ -376,10 +376,10 @@ int CMerkleTx::SetMerkleBranch(const CBlock* pblock)
hashBlock = pblock->GetHash(); hashBlock = pblock->GetHash();
// Locate the transaction // Locate the transaction
for (nIndex = 0; nIndex < pblock->vtx.size(); nIndex++) for (nIndex = 0; nIndex < (int)pblock->vtx.size(); nIndex++)
if (pblock->vtx[nIndex] == *(CTransaction*)this) if (pblock->vtx[nIndex] == *(CTransaction*)this)
break; break;
if (nIndex == pblock->vtx.size()) if (nIndex == (int)pblock->vtx.size())
{ {
vMerkleBranch.clear(); vMerkleBranch.clear();
nIndex = -1; nIndex = -1;
@ -2750,7 +2750,7 @@ bool ProcessMessages(CNode* pfrom)
int nHeaderSize = vRecv.GetSerializeSize(CMessageHeader()); int nHeaderSize = vRecv.GetSerializeSize(CMessageHeader());
if (vRecv.end() - pstart < nHeaderSize) if (vRecv.end() - pstart < nHeaderSize)
{ {
if (vRecv.size() > nHeaderSize) if ((int)vRecv.size() > nHeaderSize)
{ {
printf("\n\nPROCESSMESSAGE MESSAGESTART NOT FOUND\n\n"); printf("\n\nPROCESSMESSAGE MESSAGESTART NOT FOUND\n\n");
vRecv.erase(vRecv.begin(), vRecv.end() - nHeaderSize); vRecv.erase(vRecv.begin(), vRecv.end() - nHeaderSize);
@ -3084,7 +3084,7 @@ unsigned int static ScanHash_CryptoPP(char* pmidstate, char* pdata, char* phash1
if ((nNonce & 0xffff) == 0) if ((nNonce & 0xffff) == 0)
{ {
nHashesDone = 0xffff+1; nHashesDone = 0xffff+1;
return -1; return (unsigned int) -1;
} }
} }
} }
@ -3461,7 +3461,7 @@ void static BitcoinMiner(CWallet *pwallet)
(char*)&hash, nHashesDone); (char*)&hash, nHashesDone);
// Check if something found // Check if something found
if (nNonceFound != -1) if (nNonceFound != (unsigned int) -1)
{ {
for (unsigned int i = 0; i < sizeof(hash)/4; i++) for (unsigned int i = 0; i < sizeof(hash)/4; i++)
((unsigned int*)&hash)[i] = ByteReverse(((unsigned int*)&hash)[i]); ((unsigned int*)&hash)[i] = ByteReverse(((unsigned int*)&hash)[i]);

2
src/main.h

@ -437,7 +437,7 @@ public:
nBlockHeight = nBestHeight; nBlockHeight = nBestHeight;
if (nBlockTime == 0) if (nBlockTime == 0)
nBlockTime = GetAdjustedTime(); nBlockTime = GetAdjustedTime();
if ((int64)nLockTime < (nLockTime < LOCKTIME_THRESHOLD ? (int64)nBlockHeight : nBlockTime)) if ((int64)nLockTime < ((int64)nLockTime < LOCKTIME_THRESHOLD ? (int64)nBlockHeight : nBlockTime))
return true; return true;
BOOST_FOREACH(const CTxIn& txin, vin) BOOST_FOREACH(const CTxIn& txin, vin)
if (!txin.IsFinal()) if (!txin.IsFinal())

2
src/protocol.cpp

@ -128,7 +128,7 @@ bool operator<(const CInv& a, const CInv& b)
bool CInv::IsKnownType() const bool CInv::IsKnownType() const
{ {
return (type >= 1 && type < ARRAYLEN(ppszTypeName)); return (type >= 1 && type < (int)ARRAYLEN(ppszTypeName));
} }
const char* CInv::GetCommand() const const char* CInv::GetCommand() const

8
src/script.cpp

@ -536,7 +536,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
return false; return false;
int n = CastToBigNum(stacktop(-1)).getint(); int n = CastToBigNum(stacktop(-1)).getint();
popstack(stack); popstack(stack);
if (n < 0 || n >= stack.size()) if (n < 0 || n >= (int)stack.size())
return false; return false;
valtype vch = stacktop(-n-1); valtype vch = stacktop(-n-1);
if (opcode == OP_ROLL) if (opcode == OP_ROLL)
@ -604,9 +604,9 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
int nEnd = nBegin + CastToBigNum(stacktop(-1)).getint(); int nEnd = nBegin + CastToBigNum(stacktop(-1)).getint();
if (nBegin < 0 || nEnd < nBegin) if (nBegin < 0 || nEnd < nBegin)
return false; return false;
if (nBegin > vch.size()) if (nBegin > (int)vch.size())
nBegin = vch.size(); nBegin = vch.size();
if (nEnd > vch.size()) if (nEnd > (int)vch.size())
nEnd = vch.size(); nEnd = vch.size();
vch.erase(vch.begin() + nEnd, vch.end()); vch.erase(vch.begin() + nEnd, vch.end());
vch.erase(vch.begin(), vch.begin() + nBegin); vch.erase(vch.begin(), vch.begin() + nBegin);
@ -625,7 +625,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
int nSize = CastToBigNum(stacktop(-1)).getint(); int nSize = CastToBigNum(stacktop(-1)).getint();
if (nSize < 0) if (nSize < 0)
return false; return false;
if (nSize > vch.size()) if (nSize > (int)vch.size())
nSize = vch.size(); nSize = vch.size();
if (opcode == OP_LEFT) if (opcode == OP_LEFT)
vch.erase(vch.begin() + nSize, vch.end()); vch.erase(vch.begin() + nSize, vch.end());

2
src/script.h

@ -467,7 +467,7 @@ public:
opcodetype opcode; opcodetype opcode;
do do
{ {
while (end() - pc >= b.size() && memcmp(&pc[0], &b[0], b.size()) == 0) while (end() - pc >= (long)b.size() && memcmp(&pc[0], &b[0], b.size()) == 0)
{ {
erase(pc, pc + b.size()); erase(pc, pc + b.size());
++nFound; ++nFound;

2
src/util.cpp

@ -283,7 +283,7 @@ int my_snprintf(char* buffer, size_t limit, const char* format, ...)
va_start(arg_ptr, format); va_start(arg_ptr, format);
int ret = _vsnprintf(buffer, limit, format, arg_ptr); int ret = _vsnprintf(buffer, limit, format, arg_ptr);
va_end(arg_ptr); va_end(arg_ptr);
if (ret < 0 || ret >= limit) if (ret < 0 || ret >= (int)limit)
{ {
ret = limit - 1; ret = limit - 1;
buffer[limit-1] = 0; buffer[limit-1] = 0;

Loading…
Cancel
Save