Merge pull request #1104 from laanwj/2012_04_clang

Enable and fix most compilation warnings
This commit is contained in:
Jeff Garzik 2012-04-15 11:39:15 -07:00
commit 5a701eb7ea
23 changed files with 65 additions and 22 deletions

View file

@ -90,8 +90,7 @@ contains(BITCOIN_NEED_QT_PLUGINS, 1) {
DEFINES += HAVE_BUILD_INFO DEFINES += HAVE_BUILD_INFO
} }
# disable quite some warnings because bitcoin core "sins" a lot QMAKE_CXXFLAGS_WARN_ON = -fdiagnostics-show-option -Wall -Wextra -Wformat -Wformat-security -Wno-invalid-offsetof -Wno-sign-compare -Wno-unused-parameter
QMAKE_CXXFLAGS_WARN_ON = -fdiagnostics-show-option -Wall -Wno-strict-aliasing -Wno-invalid-offsetof -Wno-unused-variable -Wno-unused-parameter -Wno-sign-compare -Wno-char-subscripts -Wno-unused-value -Wno-sequence-point -Wno-parentheses -Wno-unknown-pragmas -Wno-switch
# Input # Input
DEPENDPATH += src/qt src src json/include DEPENDPATH += src/qt src src json/include

View file

@ -54,9 +54,15 @@ child = Popen(['xgettext','--output=-','-n','--keyword=_'] + files, stdout=PIPE)
messages = parse_po(out) messages = parse_po(out)
f = open(OUT_CPP, 'w') f = open(OUT_CPP, 'w')
f.write('#include <QtGlobal>\n') f.write("""#include <QtGlobal>
f.write('// Automatically generated by extract_strings.py\n') // Automatically generated by extract_strings.py
f.write('static const char *bitcoin_strings[] = {') #ifdef __GNUC__
#define UNUSED __attribute__((unused))
#else
#define UNUSED
#endif
""")
f.write('static const char UNUSED *bitcoin_strings[] = {')
for (msgid, msgstr) in messages: for (msgid, msgstr) in messages:
if msgid != EMPTY: if msgid != EMPTY:
f.write('QT_TRANSLATE_NOOP("bitcoin-core", %s),\n' % ('\n'.join(msgid))) f.write('QT_TRANSLATE_NOOP("bitcoin-core", %s),\n' % ('\n'.join(msgid)))

View file

@ -312,7 +312,7 @@ bool CAddrMan::Add_(const CAddress &addr, const CNetAddr& source, int64 nTimePen
pinfo->nServices |= addr.nServices; pinfo->nServices |= addr.nServices;
// do not update if no new information is present // do not update if no new information is present
if (!addr.nTime || pinfo->nTime && addr.nTime <= pinfo->nTime) if (!addr.nTime || (pinfo->nTime && addr.nTime <= pinfo->nTime))
return false; return false;
// do not update if the entry was already in the "tried" table // do not update if the entry was already in the "tried" table

View file

@ -301,7 +301,7 @@ public:
while (isxdigit(*psz)) while (isxdigit(*psz))
{ {
*this <<= 4; *this <<= 4;
int n = phexdigit[*psz++]; int n = phexdigit[(unsigned char)*psz++];
*this += n; *this += n;
} }
if (fNegative) if (fNegative)

View file

@ -796,8 +796,10 @@ Value getbalance(const Array& params, bool fHelp)
list<pair<CBitcoinAddress, int64> > listSent; list<pair<CBitcoinAddress, int64> > listSent;
wtx.GetAmounts(allGeneratedImmature, allGeneratedMature, listReceived, listSent, allFee, strSentAccount); wtx.GetAmounts(allGeneratedImmature, allGeneratedMature, listReceived, listSent, allFee, strSentAccount);
if (wtx.GetDepthInMainChain() >= nMinDepth) if (wtx.GetDepthInMainChain() >= nMinDepth)
{
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress,int64)& r, listReceived) BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress,int64)& r, listReceived)
nBalance += r.second; nBalance += r.second;
}
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress,int64)& r, listSent) BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress,int64)& r, listSent)
nBalance -= r.second; nBalance -= r.second;
nBalance -= allFee; nBalance -= allFee;
@ -1228,6 +1230,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
// Received // Received
if (listReceived.size() > 0 && wtx.GetDepthInMainChain() >= nMinDepth) if (listReceived.size() > 0 && wtx.GetDepthInMainChain() >= nMinDepth)
{
BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, int64)& r, listReceived) BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, int64)& r, listReceived)
{ {
string account; string account;
@ -1245,6 +1248,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
ret.push_back(entry); ret.push_back(entry);
} }
} }
}
} }
void AcentryToJSON(const CAccountingEntry& acentry, const string& strAccount, Array& ret) void AcentryToJSON(const CAccountingEntry& acentry, const string& strAccount, Array& ret)

View file

@ -642,6 +642,7 @@ bool CTxDB::LoadBlockIndex()
// check level 4: check whether spent txouts were spent within the main chain // check level 4: check whether spent txouts were spent within the main chain
int nOutput = 0; int nOutput = 0;
if (nCheckLevel>3) if (nCheckLevel>3)
{
BOOST_FOREACH(const CDiskTxPos &txpos, txindex.vSpent) BOOST_FOREACH(const CDiskTxPos &txpos, txindex.vSpent)
{ {
if (!txpos.IsNull()) if (!txpos.IsNull())
@ -683,8 +684,10 @@ bool CTxDB::LoadBlockIndex()
nOutput++; nOutput++;
} }
} }
}
// check level 5: check whether all prevouts are marked spent // check level 5: check whether all prevouts are marked spent
if (nCheckLevel>4) if (nCheckLevel>4)
{
BOOST_FOREACH(const CTxIn &txin, tx.vin) BOOST_FOREACH(const CTxIn &txin, tx.vin)
{ {
CTxIndex txindex; CTxIndex txindex;
@ -698,6 +701,7 @@ bool CTxDB::LoadBlockIndex()
} }
} }
} }
}
if (pindexFork) if (pindexFork)
{ {
// Reorg back to the fork // Reorg back to the fork

View file

@ -15,6 +15,8 @@ protected:
mutable CCriticalSection cs_KeyStore; mutable CCriticalSection cs_KeyStore;
public: public:
virtual ~CKeyStore() {}
// Add a key to the store. // Add a key to the store.
virtual bool AddKey(const CKey& key) =0; virtual bool AddKey(const CKey& key) =0;

View file

@ -1261,14 +1261,18 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex)
// This rule applies to all blocks whose timestamp is after March 15, 2012, 0:00 UTC. // This rule applies to all blocks whose timestamp is after March 15, 2012, 0:00 UTC.
// On testnet it is enabled as of februari 20, 2012, 0:00 UTC. // On testnet it is enabled as of februari 20, 2012, 0:00 UTC.
if (pindex->nTime > 1331769600 || (fTestNet && pindex->nTime > 1329696000)) if (pindex->nTime > 1331769600 || (fTestNet && pindex->nTime > 1329696000))
{
BOOST_FOREACH(CTransaction& tx, vtx) BOOST_FOREACH(CTransaction& tx, vtx)
{ {
CTxIndex txindexOld; CTxIndex txindexOld;
if (txdb.ReadTxIndex(tx.GetHash(), txindexOld)) if (txdb.ReadTxIndex(tx.GetHash(), txindexOld))
{
BOOST_FOREACH(CDiskTxPos &pos, txindexOld.vSpent) BOOST_FOREACH(CDiskTxPos &pos, txindexOld.vSpent)
if (pos.IsNull()) if (pos.IsNull())
return false; return false;
} }
}
}
// BIP16 didn't become active until Apr 1 2012 (Feb 15 on testnet) // BIP16 didn't become active until Apr 1 2012 (Feb 15 on testnet)
int64 nBIP16SwitchTime = fTestNet ? 1329264000 : 1333238400; int64 nBIP16SwitchTime = fTestNet ? 1329264000 : 1333238400;

View file

@ -573,9 +573,11 @@ public:
// To limit dust spam, require MIN_TX_FEE/MIN_RELAY_TX_FEE if any output is less than 0.01 // To limit dust spam, require MIN_TX_FEE/MIN_RELAY_TX_FEE if any output is less than 0.01
if (nMinFee < nBaseFee) if (nMinFee < nBaseFee)
{
BOOST_FOREACH(const CTxOut& txout, vout) BOOST_FOREACH(const CTxOut& txout, vout)
if (txout.nValue < CENT) if (txout.nValue < CENT)
nMinFee = nBaseFee; nMinFee = nBaseFee;
}
// Raise the price as the block approaches full // Raise the price as the block approaches full
if (nBlockSize != 1 && nNewBlockSize >= MAX_BLOCK_SIZE_GEN/2) if (nBlockSize != 1 && nNewBlockSize >= MAX_BLOCK_SIZE_GEN/2)

View file

@ -62,7 +62,7 @@ CFLAGS = -g
endif endif
# ppc doesn't work because we don't support big-endian # ppc doesn't work because we don't support big-endian
CFLAGS += -Wextra -Wno-sign-compare -Wno-char-subscripts -Wno-invalid-offsetof -Wformat-security \ CFLAGS += -Wextra -Wno-sign-compare -Wno-invalid-offsetof -Wformat-security \
$(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS) $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS)
OBJS= \ OBJS= \

View file

@ -81,7 +81,7 @@ LIBS+= \
DEBUGFLAGS=-g DEBUGFLAGS=-g
CXXFLAGS=-O2 CXXFLAGS=-O2
xCXXFLAGS=-pthread -Wextra -Wno-sign-compare -Wno-char-subscripts -Wno-invalid-offsetof -Wformat -Wformat-security \ xCXXFLAGS=-pthread -Wall -Wextra -Wno-sign-compare -Wno-invalid-offsetof -Wno-unused-parameter -Wformat -Wformat-security \
$(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS) $(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS)
OBJS= \ OBJS= \

View file

@ -1233,8 +1233,6 @@ void ThreadOpenConnections2(void* parg)
if (fShutdown) if (fShutdown)
return; return;
bool fAddSeeds = false;
// Add seed nodes if IRC isn't working // Add seed nodes if IRC isn't working
bool fTOR = (fUseProxy && addrProxy.GetPort() == 9050); bool fTOR = (fUseProxy && addrProxy.GetPort() == 9050);
if (addrman.size()==0 && (GetTime() - nStart > 60 || fTOR) && !fTestNet) if (addrman.size()==0 && (GetTime() - nStart > 60 || fTOR) && !fTestNet)
@ -1260,7 +1258,6 @@ void ThreadOpenConnections2(void* parg)
// Choose an address to connect to based on most recently seen // Choose an address to connect to based on most recently seen
// //
CAddress addrConnect; CAddress addrConnect;
int64 nBest = std::numeric_limits<int64>::min();
// Only connect to one address per a.b.?.? range. // Only connect to one address per a.b.?.? range.
// Do this here so we don't have to critsect vNodes inside mapAddresses critsect. // Do this here so we don't have to critsect vNodes inside mapAddresses critsect.

View file

@ -27,8 +27,9 @@ struct AddressTableEntry
}; };
// Private implementation // Private implementation
struct AddressTablePriv class AddressTablePriv
{ {
public:
CWallet *wallet; CWallet *wallet;
QList<AddressTableEntry> cachedAddressTable; QList<AddressTableEntry> cachedAddressTable;

View file

@ -1,6 +1,11 @@
#include <QtGlobal> #include <QtGlobal>
// Automatically generated by extract_strings.py // Automatically generated by extract_strings.py
static const char *bitcoin_strings[] = {QT_TRANSLATE_NOOP("bitcoin-core", "" #ifdef __GNUC__
#define UNUSED __attribute__((unused))
#else
#define UNUSED
#endif
static const char UNUSED *bitcoin_strings[] = {QT_TRANSLATE_NOOP("bitcoin-core", ""
"Unable to bind to port %d on this computer. Bitcoin is probably already " "Unable to bind to port %d on this computer. Bitcoin is probably already "
"running."), "running."),
QT_TRANSLATE_NOOP("bitcoin-core", "Warning: Disk space is low "), QT_TRANSLATE_NOOP("bitcoin-core", "Warning: Disk space is low "),

View file

@ -106,6 +106,9 @@ void EditAddressDialog::accept()
tr("New key generation failed."), tr("New key generation failed."),
QMessageBox::Ok, QMessageBox::Ok); QMessageBox::Ok, QMessageBox::Ok);
return; return;
case AddressTableModel::OK:
// Failed with unknown reason. Just reject.
break;
} }
return; return;

View file

@ -154,6 +154,8 @@ void SendCoinsDialog::on_sendButton_clicked()
tr("Error: The transaction was rejected. This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here."), tr("Error: The transaction was rejected. This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here."),
QMessageBox::Ok, QMessageBox::Ok); QMessageBox::Ok, QMessageBox::Ok);
break; break;
case WalletModel::Aborted: // User aborted, nothing to do
break;
case WalletModel::OK: case WalletModel::OK:
accept(); accept();
break; break;

View file

@ -45,8 +45,9 @@ struct TxLessThan
}; };
// Private implementation // Private implementation
struct TransactionTablePriv class TransactionTablePriv
{ {
public:
TransactionTablePriv(CWallet *wallet, TransactionTableModel *parent): TransactionTablePriv(CWallet *wallet, TransactionTableModel *parent):
wallet(wallet), wallet(wallet),
parent(parent) parent(parent)

View file

@ -35,8 +35,7 @@ public:
DuplicateAddress, DuplicateAddress,
TransactionCreationFailed, // Error returned when wallet is still locked TransactionCreationFailed, // Error returned when wallet is still locked
TransactionCommitFailed, TransactionCommitFailed,
Aborted, Aborted
MiscError
}; };
enum EncryptionStatus enum EncryptionStatus

View file

@ -1443,7 +1443,6 @@ bool ExtractAddresses(const CScript& scriptPubKey, txnouttype& typeRet, vector<C
if (typeRet == TX_MULTISIG) if (typeRet == TX_MULTISIG)
{ {
nRequiredRet = vSolutions.front()[0]; nRequiredRet = vSolutions.front()[0];
int n = vSolutions.back()[0];
for (int i = 1; i < vSolutions.size()-1; i++) for (int i = 1; i < vSolutions.size()-1; i++)
{ {
CBitcoinAddress address; CBitcoinAddress address;

View file

@ -308,7 +308,7 @@ public:
// hex string to uint // hex string to uint
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 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 };
const char* pbegin = psz; const char* pbegin = psz;
while (phexdigit[*psz] || *psz == '0') while (phexdigit[(unsigned char)*psz] || *psz == '0')
psz++; psz++;
psz--; psz--;
unsigned char* p1 = (unsigned char*)pn; unsigned char* p1 = (unsigned char*)pn;

View file

@ -6,6 +6,17 @@
#include "headers.h" #include "headers.h"
#include "strlcpy.h" #include "strlcpy.h"
#include <boost/algorithm/string/join.hpp> #include <boost/algorithm/string/join.hpp>
// Work around clang compilation problem in Boost 1.46:
// /usr/include/boost/program_options/detail/config_file.hpp:163:17: error: call to function 'to_internal' that is neither visible in the template definition nor found by argument-dependent lookup
// See also: http://stackoverflow.com/questions/10020179/compilation-fail-in-boost-librairies-program-options
// http://clang.debian.net/status.php?version=3.0&key=CANNOT_FIND_FUNCTION
namespace boost {
namespace program_options {
std::string to_internal(const std::string&);
}
}
#include <boost/program_options/detail/config_file.hpp> #include <boost/program_options/detail/config_file.hpp>
#include <boost/program_options/parsers.hpp> #include <boost/program_options/parsers.hpp>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
@ -625,7 +636,7 @@ vector<unsigned char> DecodeBase64(const char* p, bool* pfInvalid)
while (1) while (1)
{ {
int dec = decode64_table[*p]; int dec = decode64_table[(unsigned char)*p];
if (dec == -1) break; if (dec == -1) break;
p++; p++;
switch (mode) switch (mode)
@ -665,12 +676,12 @@ vector<unsigned char> DecodeBase64(const char* p, bool* pfInvalid)
break; break;
case 2: // 4n+2 base64 characters processed: require '==' case 2: // 4n+2 base64 characters processed: require '=='
if (left || p[0] != '=' || p[1] != '=' || decode64_table[p[2]] != -1) if (left || p[0] != '=' || p[1] != '=' || decode64_table[(unsigned char)p[2]] != -1)
*pfInvalid = true; *pfInvalid = true;
break; break;
case 3: // 4n+3 base64 characters processed: require '=' case 3: // 4n+3 base64 characters processed: require '='
if (left || p[0] != '=' || decode64_table[p[1]] != -1) if (left || p[0] != '=' || decode64_table[(unsigned char)p[1]] != -1)
*pfInvalid = true; *pfInvalid = true;
break; break;
} }

View file

@ -648,11 +648,13 @@ void CWalletTx::AddSupportingTransactions(CTxDB& txdb)
vtxPrev.push_back(tx); vtxPrev.push_back(tx);
if (nDepth < COPY_DEPTH) if (nDepth < COPY_DEPTH)
{
BOOST_FOREACH(const CTxIn& txin, tx.vin) BOOST_FOREACH(const CTxIn& txin, tx.vin)
vWorkQueue.push_back(txin.prevout.hash); vWorkQueue.push_back(txin.prevout.hash);
} }
} }
} }
}
reverse(vtxPrev.begin(), vtxPrev.end()); reverse(vtxPrev.begin(), vtxPrev.end());
} }

View file

@ -553,8 +553,10 @@ public:
return false; return false;
if (mapPrev.empty()) if (mapPrev.empty())
{
BOOST_FOREACH(const CMerkleTx& tx, vtxPrev) BOOST_FOREACH(const CMerkleTx& tx, vtxPrev)
mapPrev[tx.GetHash()] = &tx; mapPrev[tx.GetHash()] = &tx;
}
BOOST_FOREACH(const CTxIn& txin, ptx->vin) BOOST_FOREACH(const CTxIn& txin, ptx->vin)
{ {