Add casts for unavoidable signed/unsigned comparisons

At these code sites, it is preferable to cast rather than change
a variable's type.
This commit is contained in:
Jeff Garzik 2012-04-22 13:51:16 -04:00 committed by Jeff Garzik
parent c0a0a93d02
commit 1d8c7a9557
8 changed files with 21 additions and 19 deletions

View file

@ -117,9 +117,9 @@ public:
{
unsigned long n = BN_get_word(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
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)

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -467,7 +467,7 @@ public:
opcodetype opcode;
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());
++nFound;

View file

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