From f9f625fb326d054a7398a9931f20ee40c737d858 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Sun, 15 Apr 2012 12:24:03 +0200 Subject: [PATCH 1/9] enable all warnings except invalid-offsetof, sign-compare, unused-parameter --- bitcoin-qt.pro | 3 +-- src/makefile.osx | 2 +- src/makefile.unix | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/bitcoin-qt.pro b/bitcoin-qt.pro index a3b42cdc2..14ee947c2 100644 --- a/bitcoin-qt.pro +++ b/bitcoin-qt.pro @@ -90,8 +90,7 @@ contains(BITCOIN_NEED_QT_PLUGINS, 1) { DEFINES += HAVE_BUILD_INFO } -# disable quite some warnings because bitcoin core "sins" a lot -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 +QMAKE_CXXFLAGS_WARN_ON = -fdiagnostics-show-option -Wall -Wextra -Wformat -Wformat-security -Wno-invalid-offsetof -Wno-sign-compare -Wno-unused-parameter # Input DEPENDPATH += src/qt src src json/include diff --git a/src/makefile.osx b/src/makefile.osx index c5d3edbdc..e2e35de5c 100644 --- a/src/makefile.osx +++ b/src/makefile.osx @@ -62,7 +62,7 @@ CFLAGS = -g endif # 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) OBJS= \ diff --git a/src/makefile.unix b/src/makefile.unix index 79251dc7a..9bc780d53 100644 --- a/src/makefile.unix +++ b/src/makefile.unix @@ -81,7 +81,7 @@ LIBS+= \ DEBUGFLAGS=-g 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) OBJS= \ From 1f29d399f449af918189f0d8a0302a74286dc6b7 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Sun, 15 Apr 2012 11:42:40 +0200 Subject: [PATCH 2/9] work around issue in boost::program_options that prevents from compiling in clang --- src/util.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/util.cpp b/src/util.cpp index 911388b37..1eda59baf 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -6,6 +6,17 @@ #include "headers.h" #include "strlcpy.h" #include + +// 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 #include #include From 8add7822cef7d39cb761f59e6b837159a4968982 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Sun, 15 Apr 2012 12:22:30 +0200 Subject: [PATCH 3/9] fix warnings: array subscript is of type 'char' [-Wchar-subscripts] --- src/bignum.h | 2 +- src/uint256.h | 2 +- src/util.cpp | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/bignum.h b/src/bignum.h index 95e21977e..daf5f6883 100644 --- a/src/bignum.h +++ b/src/bignum.h @@ -301,7 +301,7 @@ public: while (isxdigit(*psz)) { *this <<= 4; - int n = phexdigit[*psz++]; + int n = phexdigit[(unsigned char)*psz++]; *this += n; } if (fNegative) diff --git a/src/uint256.h b/src/uint256.h index cfc2eb128..094781678 100644 --- a/src/uint256.h +++ b/src/uint256.h @@ -308,7 +308,7 @@ public: // 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 }; const char* pbegin = psz; - while (phexdigit[*psz] || *psz == '0') + while (phexdigit[(unsigned char)*psz] || *psz == '0') psz++; psz--; unsigned char* p1 = (unsigned char*)pn; diff --git a/src/util.cpp b/src/util.cpp index 1eda59baf..a5427c061 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -636,7 +636,7 @@ vector DecodeBase64(const char* p, bool* pfInvalid) while (1) { - int dec = decode64_table[*p]; + int dec = decode64_table[(unsigned char)*p]; if (dec == -1) break; p++; switch (mode) @@ -676,12 +676,12 @@ vector DecodeBase64(const char* p, bool* pfInvalid) break; 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; break; 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; break; } From 87207a2e08b8ce829e9f9839675637596f204f99 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Sun, 15 Apr 2012 12:31:56 +0200 Subject: [PATCH 4/9] fix warnings: 'XX' defined as a struct here but previously declared as a class [-Wmismatched-tags] --- src/qt/addresstablemodel.cpp | 3 ++- src/qt/transactiontablemodel.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/qt/addresstablemodel.cpp b/src/qt/addresstablemodel.cpp index 05f3a8169..0239a167d 100644 --- a/src/qt/addresstablemodel.cpp +++ b/src/qt/addresstablemodel.cpp @@ -27,8 +27,9 @@ struct AddressTableEntry }; // Private implementation -struct AddressTablePriv +class AddressTablePriv { +public: CWallet *wallet; QList cachedAddressTable; diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp index aa11df979..41c9db112 100644 --- a/src/qt/transactiontablemodel.cpp +++ b/src/qt/transactiontablemodel.cpp @@ -45,8 +45,9 @@ struct TxLessThan }; // Private implementation -struct TransactionTablePriv +class TransactionTablePriv { +public: TransactionTablePriv(CWallet *wallet, TransactionTableModel *parent): wallet(wallet), parent(parent) From 76d8170ce8b4714657f8defd791bd30fef1a8de4 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Sun, 15 Apr 2012 12:42:52 +0200 Subject: [PATCH 5/9] fix warnings: enumeration values 'XX' not handled in switch [-Wswitch-enum] --- src/qt/editaddressdialog.cpp | 3 +++ src/qt/sendcoinsdialog.cpp | 2 ++ src/qt/walletmodel.h | 3 +-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/qt/editaddressdialog.cpp b/src/qt/editaddressdialog.cpp index 8cc3c85d7..cecb8aecd 100644 --- a/src/qt/editaddressdialog.cpp +++ b/src/qt/editaddressdialog.cpp @@ -106,6 +106,9 @@ void EditAddressDialog::accept() tr("New key generation failed."), QMessageBox::Ok, QMessageBox::Ok); return; + case AddressTableModel::OK: + // Failed with unknown reason. Just reject. + break; } return; diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index 592ae6f45..b4029aa0d 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -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."), QMessageBox::Ok, QMessageBox::Ok); break; + case WalletModel::Aborted: // User aborted, nothing to do + break; case WalletModel::OK: accept(); break; diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index c4468171a..6c47f61be 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -35,8 +35,7 @@ public: DuplicateAddress, TransactionCreationFailed, // Error returned when wallet is still locked TransactionCommitFailed, - Aborted, - MiscError + Aborted }; enum EncryptionStatus From 11cd41652519be7053b16847ffa2a7c7df64b95d Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Sun, 15 Apr 2012 12:53:14 +0200 Subject: [PATCH 6/9] fix warnings: unused variable 'XX' [-Wunused-variable] --- share/qt/extract_strings_qt.py | 12 +++++++++--- src/net.cpp | 3 --- src/qt/bitcoinstrings.cpp | 7 ++++++- src/script.cpp | 1 - 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/share/qt/extract_strings_qt.py b/share/qt/extract_strings_qt.py index 03d3a1ba3..771f28ab0 100755 --- a/share/qt/extract_strings_qt.py +++ b/share/qt/extract_strings_qt.py @@ -54,9 +54,15 @@ child = Popen(['xgettext','--output=-','-n','--keyword=_'] + files, stdout=PIPE) messages = parse_po(out) f = open(OUT_CPP, 'w') -f.write('#include \n') -f.write('// Automatically generated by extract_strings.py\n') -f.write('static const char *bitcoin_strings[] = {') +f.write("""#include +// Automatically generated by extract_strings.py +#ifdef __GNUC__ +#define UNUSED __attribute__((unused)) +#else +#define UNUSED +#endif +""") +f.write('static const char UNUSED *bitcoin_strings[] = {') for (msgid, msgstr) in messages: if msgid != EMPTY: f.write('QT_TRANSLATE_NOOP("bitcoin-core", %s),\n' % ('\n'.join(msgid))) diff --git a/src/net.cpp b/src/net.cpp index 8272b2556..b0f365061 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1233,8 +1233,6 @@ void ThreadOpenConnections2(void* parg) if (fShutdown) return; - bool fAddSeeds = false; - // Add seed nodes if IRC isn't working bool fTOR = (fUseProxy && addrProxy.GetPort() == 9050); 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 // CAddress addrConnect; - int64 nBest = std::numeric_limits::min(); // Only connect to one address per a.b.?.? range. // Do this here so we don't have to critsect vNodes inside mapAddresses critsect. diff --git a/src/qt/bitcoinstrings.cpp b/src/qt/bitcoinstrings.cpp index 4fbd9874f..b25af1a21 100644 --- a/src/qt/bitcoinstrings.cpp +++ b/src/qt/bitcoinstrings.cpp @@ -1,6 +1,11 @@ #include // 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 " "running."), QT_TRANSLATE_NOOP("bitcoin-core", "Warning: Disk space is low "), diff --git a/src/script.cpp b/src/script.cpp index b6f120289..21f101e1c 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -1443,7 +1443,6 @@ bool ExtractAddresses(const CScript& scriptPubKey, txnouttype& typeRet, vector Date: Sun, 15 Apr 2012 12:59:20 +0200 Subject: [PATCH 7/9] fix warnings: delete called on 'XX' that has virtual functions but non-virtual destructor [-Wdelete-non-virtual-dtor] --- src/keystore.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/keystore.h b/src/keystore.h index 282eaaa04..5d29ac1cb 100644 --- a/src/keystore.h +++ b/src/keystore.h @@ -15,6 +15,8 @@ protected: mutable CCriticalSection cs_KeyStore; public: + virtual ~CKeyStore() {} + // Add a key to the store. virtual bool AddKey(const CKey& key) =0; From 6642ffb761cc04c990510d8a5e89714e003abb77 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Sun, 15 Apr 2012 13:03:28 +0200 Subject: [PATCH 8/9] fix warnings: '&&' within '||' [-Wlogical-op-parentheses] --- src/addrman.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/addrman.cpp b/src/addrman.cpp index 2ef666cf2..8fb40b46d 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -312,7 +312,7 @@ bool CAddrMan::Add_(const CAddress &addr, const CNetAddr& source, int64 nTimePen pinfo->nServices |= addr.nServices; // 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; // do not update if the entry was already in the "tried" table From da7bbd9dfdb8914977fc254b0c9b1bb3025726c8 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Sun, 15 Apr 2012 13:27:00 +0200 Subject: [PATCH 9/9] fix warnings: suggest explicit braces to avoid ambiguous 'else' [-Wparentheses] --- src/bitcoinrpc.cpp | 4 ++++ src/db.cpp | 4 ++++ src/main.cpp | 4 ++++ src/main.h | 2 ++ src/wallet.cpp | 2 ++ src/wallet.h | 2 ++ 6 files changed, 18 insertions(+) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 7c991144d..63c51ada8 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -796,8 +796,10 @@ Value getbalance(const Array& params, bool fHelp) list > listSent; wtx.GetAmounts(allGeneratedImmature, allGeneratedMature, listReceived, listSent, allFee, strSentAccount); if (wtx.GetDepthInMainChain() >= nMinDepth) + { BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress,int64)& r, listReceived) nBalance += r.second; + } BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress,int64)& r, listSent) nBalance -= r.second; nBalance -= allFee; @@ -1228,6 +1230,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe // Received if (listReceived.size() > 0 && wtx.GetDepthInMainChain() >= nMinDepth) + { BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, int64)& r, listReceived) { string account; @@ -1245,6 +1248,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe ret.push_back(entry); } } + } } void AcentryToJSON(const CAccountingEntry& acentry, const string& strAccount, Array& ret) diff --git a/src/db.cpp b/src/db.cpp index 839c0807c..2d136914c 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -642,6 +642,7 @@ bool CTxDB::LoadBlockIndex() // check level 4: check whether spent txouts were spent within the main chain int nOutput = 0; if (nCheckLevel>3) + { BOOST_FOREACH(const CDiskTxPos &txpos, txindex.vSpent) { if (!txpos.IsNull()) @@ -682,9 +683,11 @@ bool CTxDB::LoadBlockIndex() } nOutput++; } + } } // check level 5: check whether all prevouts are marked spent if (nCheckLevel>4) + { BOOST_FOREACH(const CTxIn &txin, tx.vin) { CTxIndex txindex; @@ -695,6 +698,7 @@ bool CTxDB::LoadBlockIndex() pindexFork = pindex->pprev; } } + } } } } diff --git a/src/main.cpp b/src/main.cpp index a6393a5c8..f2932804e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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. // On testnet it is enabled as of februari 20, 2012, 0:00 UTC. if (pindex->nTime > 1331769600 || (fTestNet && pindex->nTime > 1329696000)) + { BOOST_FOREACH(CTransaction& tx, vtx) { CTxIndex txindexOld; if (txdb.ReadTxIndex(tx.GetHash(), txindexOld)) + { BOOST_FOREACH(CDiskTxPos &pos, txindexOld.vSpent) if (pos.IsNull()) return false; + } } + } // BIP16 didn't become active until Apr 1 2012 (Feb 15 on testnet) int64 nBIP16SwitchTime = fTestNet ? 1329264000 : 1333238400; diff --git a/src/main.h b/src/main.h index 723f4e150..a89c0935f 100644 --- a/src/main.h +++ b/src/main.h @@ -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 if (nMinFee < nBaseFee) + { BOOST_FOREACH(const CTxOut& txout, vout) if (txout.nValue < CENT) nMinFee = nBaseFee; + } // Raise the price as the block approaches full if (nBlockSize != 1 && nNewBlockSize >= MAX_BLOCK_SIZE_GEN/2) diff --git a/src/wallet.cpp b/src/wallet.cpp index 97ed6aa58..ff10e0cef 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -648,8 +648,10 @@ void CWalletTx::AddSupportingTransactions(CTxDB& txdb) vtxPrev.push_back(tx); if (nDepth < COPY_DEPTH) + { BOOST_FOREACH(const CTxIn& txin, tx.vin) vWorkQueue.push_back(txin.prevout.hash); + } } } } diff --git a/src/wallet.h b/src/wallet.h index f864370ac..869e888fc 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -553,8 +553,10 @@ public: return false; if (mapPrev.empty()) + { BOOST_FOREACH(const CMerkleTx& tx, vtxPrev) mapPrev[tx.GetHash()] = &tx; + } BOOST_FOREACH(const CTxIn& txin, ptx->vin) {