Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sign comparison warnings #437

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion paycoin-qt.pro
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ contains(BITCOIN_NEED_QT_PLUGINS, 1) {
DEFINES += HAVE_BUILD_INFO
}

QMAKE_CXXFLAGS_WARN_ON = -Wall -Wextra -Wformat -Wformat-security -Wno-invalid-offsetof -Wno-sign-compare -Wno-unused-parameter
QMAKE_CXXFLAGS_WARN_ON = -Wall -Wextra -Wformat -Wformat-security -Wno-invalid-offsetof -Wno-unused-parameter
# this option unrecognized when building on OSX 10.6.8
!macx {
QMAKE_CXXFLAGS_WARN_ON += -fdiagnostics-show-option
Expand Down
5 changes: 2 additions & 3 deletions src/addrman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,11 @@ CAddrInfo* CAddrMan::Create(const CAddress &addr, const CNetAddr &addrSource, in
return &mapInfo[nId];
}

void CAddrMan::SwapRandom(int nRndPos1, int nRndPos2)
void CAddrMan::SwapRandom(unsigned int nRndPos1, unsigned int nRndPos2)
{
if (nRndPos1 == nRndPos2)
return;

assert(nRndPos1 >= 0 && nRndPos2 >= 0);
assert(nRndPos1 < vRandom.size() && nRndPos2 < vRandom.size());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So essentially this is meant to ensure that the RndPos# variables are positive...

I'm wondering if there is any chance that they could ever be negative (if they were and this was left in place it would actually crash the application; I'm not sure what the behavior would be with this check missing); just because it was removed in Bitcoin doesn't necessarily mean it's safe or a good idea for us to remove it though...

Thoughts?


int nId1 = vRandom[nRndPos1];
Expand Down Expand Up @@ -150,7 +149,7 @@ int CAddrMan::SelectTried(int nKBucket)

int CAddrMan::ShrinkNew(int nUBucket)
{
assert(nUBucket >= 0 && nUBucket < vvNew.size());
assert(nUBucket >= 0 && (unsigned int)nUBucket < vvNew.size());
std::set<int> &vNew = vvNew[nUBucket];

// first look for deletable items
Expand Down
2 changes: 1 addition & 1 deletion src/addrman.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class CAddrMan
CAddrInfo* Create(const CAddress &addr, const CNetAddr &addrSource, int *pnId = NULL);

// Swap two elements in vRandom.
void SwapRandom(int nRandomPos1, int nRandomPos2);
void SwapRandom(unsigned int nRandomPos1, unsigned int nRandomPos2);

// Return position in given bucket to replace.
int SelectTried(int nKBucket);
Expand Down
2 changes: 1 addition & 1 deletion src/bignum.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class CBigNum : public BIGNUM
if (vch.size() > 4)
vch[4] &= 0x7f;
uint64 n = 0;
for (int i = 0, j = vch.size()-1; i < sizeof(n) && j >= 4; i++, j--)
for (unsigned int i = 0, j = vch.size()-1; i < sizeof(n) && j >= 4; i++, j--)
((unsigned char*)&n)[i] = vch[j];
return n;
}
Expand Down
4 changes: 2 additions & 2 deletions src/bitcoinrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ Value gettxout(const Array& params, bool fHelp)
if (mempool.exists(hash))
{
tx = mempool.lookup(hash);
if (n >= tx.vout.size())
if (n >= (int)tx.vout.size())
return Value::null;
fFound = true;
fInMempool = true;
Expand All @@ -652,7 +652,7 @@ Value gettxout(const Array& params, bool fHelp)
CTxIndex txindex;
if (!txdb.ReadTxIndex(hash, txindex))
return Value::null;
if (n >= txindex.vSpent.size())
if (n >= (int)txindex.vSpent.size())
return Value::null;
if (!txindex.vSpent[n].IsNull())
return Value::null;
Expand Down
2 changes: 1 addition & 1 deletion src/kernelrecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ vector<KernelRecord> KernelRecord::decomposeOutput(const CWallet *wallet, const

if (showTransaction(wtx))
{
for (int nOut = 0; nOut < wtx.vout.size(); nOut++)
for (unsigned int nOut = 0; nOut < wtx.vout.size(); nOut++)
{
CTxOut txOut = wtx.vout[nOut];
if( wallet->IsMine(txOut) ) {
Expand Down
8 changes: 4 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ bool CTransaction::CheckTransaction() const

// Check for negative or overflow output values
int64 nValueOut = 0;
for (int i = 0; i < vout.size(); i++)
for (unsigned int i = 0; i < vout.size(); i++)
{
const CTxOut& txout = vout[i];
if (txout.IsEmpty() && (!IsCoinBase()) && (!IsCoinStake()))
Expand Down Expand Up @@ -2039,7 +2039,7 @@ bool CBlock::CheckBlock(int64 nHeight) const
return DoS(100, error("CheckBlock() : more than one coinbase"));

// paycoin: only the second transaction can be the optional coinstake
for (int i = 2; i < vtx.size(); i++)
for (unsigned int i = 2; i < vtx.size(); i++)
if (vtx[i].IsCoinStake())
return DoS(100, error("CheckBlock() : coinstake in wrong position"));

Expand Down Expand Up @@ -2385,7 +2385,7 @@ bool CheckDiskSpace(uint64 nAdditionalBytes)

FILE* OpenBlockFile(unsigned int nFile, unsigned int nBlockPos, const char* pszMode)
{
if (nFile == -1)
if ((nFile < 1) || (nFile == (unsigned int) -1))
return NULL;
FILE* file = fopen((GetDataDir() / strprintf("blk%04d.dat", nFile)).string().c_str(), pszMode);
if (!file)
Expand Down Expand Up @@ -2414,7 +2414,7 @@ FILE* AppendBlockFile(unsigned int& nFileRet)
if (fseek(file, 0, SEEK_END) != 0)
return NULL;
// FAT32 filesize max 4GB, fseek and ftell max 2GB, so we must stay under 2GB
if (ftell(file) < 0x7F000000 - MAX_SIZE)
if (ftell(file) < 0x7F000000 - (int)MAX_SIZE)
{
nFileRet = nCurrentBlockFile;
return file;
Expand Down
14 changes: 7 additions & 7 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static const int64 MIN_TXOUT_AMOUNT = MIN_TX_FEE;
inline bool MoneyRange(int64 nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }
static const int COINBASE_MATURITY_PPC = 100;
// Threshold for nLockTime: below this value it is interpreted as block number, otherwise as UNIX timestamp.
static const int LOCKTIME_THRESHOLD = 500000000; // Tue Nov 5 00:53:20 1985 UTC
static const unsigned int LOCKTIME_THRESHOLD = 500000000; // Tue Nov 5 00:53:20 1985 UTC
static const int STAKE_TARGET_SPACING = 1 * 60; // 1-minute block
static const int STAKE_MIN_AGE = 60 * 60; // minimum age for coin age
static const int STAKE_MAX_AGE = 60 * 60 * 24 * 5; // stake age of full weight
Expand Down Expand Up @@ -166,8 +166,8 @@ class CDiskTxPos
}

IMPLEMENT_SERIALIZE( READWRITE(FLATDATA(*this)); )
void SetNull() { nFile = -1; nBlockPos = 0; nTxPos = 0; }
bool IsNull() const { return (nFile == -1); }
void SetNull() { nFile = (unsigned int) -1; nBlockPos = 0; nTxPos = 0; }
bool IsNull() const { return (nFile == (unsigned int) -1); }

friend bool operator==(const CDiskTxPos& a, const CDiskTxPos& b)
{
Expand Down Expand Up @@ -206,8 +206,8 @@ class CInPoint

CInPoint() { SetNull(); }
CInPoint(CTransaction* ptxIn, unsigned int nIn) { ptx = ptxIn; n = nIn; }
void SetNull() { ptx = NULL; n = -1; }
bool IsNull() const { return (ptx == NULL && n == -1); }
void SetNull() { ptx = NULL; n = (unsigned int) -1; }
bool IsNull() const { return (ptx == NULL && n == (unsigned int) -1); }
};


Expand All @@ -222,8 +222,8 @@ class COutPoint
COutPoint() { SetNull(); }
COutPoint(uint256 hashIn, unsigned int nIn) { hash = hashIn; n = nIn; }
IMPLEMENT_SERIALIZE( READWRITE(FLATDATA(*this)); )
void SetNull() { hash = 0; n = -1; }
bool IsNull() const { return (hash == 0 && n == -1); }
void SetNull() { hash = 0; n = (unsigned int) -1; }
bool IsNull() const { return (hash == 0 && n == (unsigned int) -1); }

friend bool operator<(const COutPoint& a, const COutPoint& b)
{
Expand Down
2 changes: 1 addition & 1 deletion src/makefile.osx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ CFLAGS = -g
endif

# ppc doesn't work because we don't support big-endian
CFLAGS += -Wextra -Wno-sign-compare -Wno-invalid-offsetof -Wformat-security \
CFLAGS += -Wextra -Wno-invalid-offsetof -Wformat-security \
$(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS)

OBJS= \
Expand Down
2 changes: 1 addition & 1 deletion src/makefile.osx-mavericks
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ CFLAGS = -g
endif

# ppc doesn't work because we don't support big-endian
CFLAGS += -w -Wextra -Wno-sign-compare -Wno-invalid-offsetof -Wformat-security \
CFLAGS += -w -Wextra -Wno-invalid-offsetof -Wformat-security \
$(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS)

OBJS= \
Expand Down
2 changes: 1 addition & 1 deletion src/makefile.unix
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ LIBS+= \

DEBUGFLAGS=-g
CXXFLAGS=-O2
xCXXFLAGS=-pthread -Wall -Wextra -Wno-sign-compare -Wno-invalid-offsetof -Wno-unused-parameter -Wformat -Wformat-security \
xCXXFLAGS=-pthread -Wall -Wextra -Wno-invalid-offsetof -Wno-unused-parameter -Wformat -Wformat-security \
$(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS)

# LDFLAGS can be specified on the make command line, so we use xLDFLAGS that only
Expand Down
10 changes: 5 additions & 5 deletions src/netbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ bool static Socks5(string strDest, int port, SOCKET& hSocket)
}
char pszSocks5Init[] = "\5\1\0";
char *pszSocks5 = pszSocks5Init;
int nSize = sizeof(pszSocks5Init) - 1;
ssize_t nSize = sizeof(pszSocks5Init) - 1;

int ret = send(hSocket, pszSocks5, nSize, MSG_NOSIGNAL);
ssize_t ret = send(hSocket, pszSocks5, nSize, MSG_NOSIGNAL);
if (ret != nSize)
{
closesocket(hSocket);
Expand All @@ -256,7 +256,7 @@ bool static Socks5(string strDest, int port, SOCKET& hSocket)
strSocks5 += static_cast<char>((port >> 8) & 0xFF);
strSocks5 += static_cast<char>((port >> 0) & 0xFF);
ret = send(hSocket, strSocks5.c_str(), strSocks5.size(), MSG_NOSIGNAL);
if (ret != strSocks5.size())
if (ret != (ssize_t)strSocks5.size())
{
closesocket(hSocket);
return error("Error sending to proxy");
Expand Down Expand Up @@ -982,7 +982,7 @@ bool operator<(const CService& a, const CService& b)
bool CService::GetSockAddr(struct sockaddr* paddr, socklen_t *addrlen) const
{
if (IsIPv4()) {
if (*addrlen < sizeof(struct sockaddr_in))
if (*addrlen < (socklen_t)sizeof(struct sockaddr_in))
return false;
*addrlen = sizeof(struct sockaddr_in);
struct sockaddr_in *paddrin = (struct sockaddr_in*)paddr;
Expand All @@ -995,7 +995,7 @@ bool CService::GetSockAddr(struct sockaddr* paddr, socklen_t *addrlen) const
}
#ifdef USE_IPV6
if (IsIPv6()) {
if (*addrlen < sizeof(struct sockaddr_in6))
if (*addrlen < (socklen_t)sizeof(struct sockaddr_in6))
return false;
*addrlen = sizeof(struct sockaddr_in6);
struct sockaddr_in6 *paddrin6 = (struct sockaddr_in6*)paddr;
Expand Down
2 changes: 1 addition & 1 deletion src/primenodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ bool CTransaction::IsPrimeStake(CScript scriptPubKeyType, CScript scriptPubKeyAd
* may be set temperately when it's known that a release will be done
* that ensures people update before the real valid_until time occurs
* and the real end date is unknown at the time of updating the keys. */
if (entry.valid_until != -1 && nTime >= entry.valid_until)
if (entry.valid_until != (unsigned int)-1 && nTime >= entry.valid_until)
return DoS(100, error("IsPrimeStake() : prime node staking has ended for the given keypair"));
}

Expand Down
4 changes: 2 additions & 2 deletions src/qt/multisigdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ void MultisigDialog::on_signTransactionButton_clicked()

// Fetch previous transactions (inputs)
std::map<COutPoint, CScript> mapPrevOut;
for(int i = 0; i < mergedTx.vin.size(); i++)
for(unsigned int i = 0; i < mergedTx.vin.size(); i++)
{
CTransaction tempTx;
MapPrevTx mapPrevTx;
Expand Down Expand Up @@ -422,7 +422,7 @@ void MultisigDialog::on_signTransactionButton_clicked()

// Sign what we can
bool fComplete = true;
for(int i = 0; i < mergedTx.vin.size(); i++)
for(unsigned int i = 0; i < mergedTx.vin.size(); i++)
{
CTxIn& txin = mergedTx.vin[i];
if(mapPrevOut.count(txin.prevout) == 0)
Expand Down
4 changes: 2 additions & 2 deletions src/qt/multisiginputentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ CTxIn MultisigInputEntry::getInput()
int64 MultisigInputEntry::getAmount()
{
int64 amount = 0;
int nOutput = ui->transactionOutput->currentIndex();
unsigned int nOutput = ui->transactionOutput->currentIndex();
CTransaction tx;
uint256 blockHash = 0;

Expand Down Expand Up @@ -115,7 +115,7 @@ void MultisigInputEntry::on_transactionId_textChanged(const QString &transaction
uint256 blockHash = 0;
if(!GetTransaction(txHash, tx, blockHash))
return;
for(int i = 0; i < tx.vout.size(); i++)
for(unsigned int i = 0; i < tx.vout.size(); i++)
{
QString idStr;
idStr.setNum(i);
Expand Down
2 changes: 1 addition & 1 deletion src/qt/transactionrecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet *
//
int64 nTxFee = nDebit - wtx.GetValueOut();

for (int nOut = 0; nOut < wtx.vout.size(); nOut++)
for (unsigned int nOut = 0; nOut < wtx.vout.size(); nOut++)
{
const CTxOut& txout = wtx.vout[nOut];
TransactionRecord sub(hash, nTime);
Expand Down
2 changes: 1 addition & 1 deletion src/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ Value listminting(const Array& params, bool fHelp)
"listminting [count=-1] [from=0]\n"
"Return all mintable outputs and provide details for each of them.");

int count = -1;
unsigned int count = -1;

if(params.size() > 0)
count = params[0].get_int();
Expand Down
6 changes: 3 additions & 3 deletions src/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
// ([sig ...] num_of_signatures [pubkey ...] num_of_pubkeys -- bool)

int i = 1;
if (stack.size() < i)
if ((int)stack.size() < i)
return false;

int nKeysCount = CastToBigNum(stacktop(-i)).getint();
Expand All @@ -961,15 +961,15 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
return false;
int ikey = ++i;
i += nKeysCount;
if (stack.size() < i)
if ((int)stack.size() < i)
return false;

int nSigsCount = CastToBigNum(stacktop(-i)).getint();
if (nSigsCount < 0 || nSigsCount > nKeysCount)
return false;
int isig = ++i;
i += nSigsCount;
if (stack.size() < i)
if ((int)stack.size() < i)
return false;

// Subset of script starting at the most recent codeseparator
Expand Down
2 changes: 1 addition & 1 deletion src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2142,7 +2142,7 @@ void CWallet::FixSpentCoins(int& nMismatchFound, int64& nBalanceInQuestion, bool
CTxIndex txindex;
if (!txdb.ReadTxIndex(pcoin->GetHash(), txindex))
continue;
for (int n=0; n < pcoin->vout.size(); n++)
for (unsigned int n = 0; n < pcoin->vout.size(); n++)
{
if (IsMine(pcoin->vout[n]) && pcoin->IsSpent(n) && (txindex.vSpent.size() <= n || txindex.vSpent[n].IsNull()))
{
Expand Down