From e177e5dd561b04922c017773df0a28b9d92947f2 Mon Sep 17 00:00:00 2001 From: tmvorisek Date: Wed, 2 May 2018 20:56:14 -0800 Subject: [PATCH] Ran clang tidy with various modernization fixes. --- src/bitcoinrpc.cpp | 4 +-- src/cryptopp/cryptlib.h | 30 ++++++++-------- src/cryptopp/smartptr.h | 2 +- src/db.cpp | 4 +-- src/gamedb.cpp | 2 +- src/huntercoin.cpp | 50 +++++++++++++------------- src/json/json_spirit_reader_template.h | 2 +- src/main.cpp | 4 +-- src/net.cpp | 4 +-- src/wallet.h | 6 ++-- 10 files changed, 54 insertions(+), 54 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 33e2fcd3..897c319a 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -2613,7 +2613,7 @@ Value getauxblock(const Array& params, bool fHelp) hash.SetHex(params[0].get_str()); vector vchAuxPow = ParseHex(params[1].get_str()); CDataStream ss(vchAuxPow, SER_GETHASH | SER_BLOCKHEADERONLY); - CAuxPow* pow = new CAuxPow(algo); + auto* pow = new CAuxPow(algo); ss >> *pow; if (!mapNewBlockSCRYPT.count(hash)) return ::error("getauxblock() : block not found"); @@ -2692,7 +2692,7 @@ Value getauxblock(const Array& params, bool fHelp) hash.SetHex(params[0].get_str()); vector vchAuxPow = ParseHex(params[1].get_str()); CDataStream ss(vchAuxPow, SER_GETHASH | SER_BLOCKHEADERONLY); - CAuxPow* pow = new CAuxPow(algo); + auto* pow = new CAuxPow(algo); ss >> *pow; if (!mapNewBlockSHA256D.count(hash)) return ::error("getauxblock() : block not found"); diff --git a/src/cryptopp/cryptlib.h b/src/cryptopp/cryptlib.h index 15cd6dad..46e0be1d 100644 --- a/src/cryptopp/cryptlib.h +++ b/src/cryptopp/cryptlib.h @@ -182,7 +182,7 @@ class CRYPTOPP_DLL OS_Error : public Exception public: OS_Error(ErrorType errorType, const std::string &s, const std::string& operation, int errorCode) : Exception(errorType, s), m_operation(operation), m_errorCode(errorCode) {} - ~OS_Error() throw() {} + ~OS_Error() throw() override override override {} // the operating system API that reported the error const std::string & GetOperation() const {return m_operation;} @@ -615,21 +615,21 @@ typedef HashTransformation HashFunction; class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BlockCipher : public SimpleKeyingInterface, public BlockTransformation { protected: - const Algorithm & GetAlgorithm() const {return *this;} + const Algorithm & GetAlgorithm() const override override override {return *this;} }; //! interface for one direction (encryption or decryption) of a stream cipher or cipher mode class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE SymmetricCipher : public SimpleKeyingInterface, public StreamTransformation { protected: - const Algorithm & GetAlgorithm() const {return *this;} + const Algorithm & GetAlgorithm() const override override override {return *this;} }; //! interface for message authentication codes class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE MessageAuthenticationCode : public SimpleKeyingInterface, public HashTransformation { protected: - const Algorithm & GetAlgorithm() const {return *this;} + const Algorithm & GetAlgorithm() const override override override {return *this;} }; //! interface for for one direction (encryption or decryption) of a stream cipher or block cipher mode with authentication @@ -666,7 +666,7 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE AuthenticatedSymmetricCipher : public Mess virtual std::string AlgorithmName() const =0; protected: - const Algorithm & GetAlgorithm() const {return *static_cast(this);} + const Algorithm & GetAlgorithm() const override override override {return *static_cast(this);} virtual void UncheckedSpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength) {} }; @@ -837,8 +837,8 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE BufferedTransformation : public Algorithm, //! \name WAITING //@{ - unsigned int GetMaxWaitObjectCount() const; - void GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack); + unsigned int GetMaxWaitObjectCount() const override override override; + void GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack) override override override; //@} //! \name SIGNALS @@ -1166,8 +1166,8 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PublicKeyAlgorithm : public AsymmetricAlgo { public: // VC60 workaround: no co-variant return type - CryptoMaterial & AccessMaterial() {return AccessPublicKey();} - const CryptoMaterial & GetMaterial() const {return GetPublicKey();} + CryptoMaterial & AccessMaterial() override override override {return AccessPublicKey();} + const CryptoMaterial & GetMaterial() const override override override {return GetPublicKey();} virtual PublicKey & AccessPublicKey() =0; virtual const PublicKey & GetPublicKey() const {return const_cast(this)->AccessPublicKey();} @@ -1178,8 +1178,8 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PublicKeyAlgorithm : public AsymmetricAlgo class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PrivateKeyAlgorithm : public AsymmetricAlgorithm { public: - CryptoMaterial & AccessMaterial() {return AccessPrivateKey();} - const CryptoMaterial & GetMaterial() const {return GetPrivateKey();} + CryptoMaterial & AccessMaterial() override override override {return AccessPrivateKey();} + const CryptoMaterial & GetMaterial() const override override override {return GetPrivateKey();} virtual PrivateKey & AccessPrivateKey() =0; virtual const PrivateKey & GetPrivateKey() const {return const_cast(this)->AccessPrivateKey();} @@ -1190,8 +1190,8 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PrivateKeyAlgorithm : public AsymmetricAlg class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE KeyAgreementAlgorithm : public AsymmetricAlgorithm { public: - CryptoMaterial & AccessMaterial() {return AccessCryptoParameters();} - const CryptoMaterial & GetMaterial() const {return GetCryptoParameters();} + CryptoMaterial & AccessMaterial() override override override {return AccessCryptoParameters();} + const CryptoMaterial & GetMaterial() const override override override {return GetCryptoParameters();} virtual CryptoParameters & AccessCryptoParameters() =0; virtual const CryptoParameters & GetCryptoParameters() const {return const_cast(this)->AccessCryptoParameters();} @@ -1348,10 +1348,10 @@ class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE PK_MessageAccumulator : public HashTransfo { public: //! should not be called on PK_MessageAccumulator - unsigned int DigestSize() const + unsigned int DigestSize() const override override override {throw NotImplemented("PK_MessageAccumulator: DigestSize() should not be called");} //! should not be called on PK_MessageAccumulator - void TruncatedFinal(byte *digest, size_t digestSize) + void TruncatedFinal(byte *digest, size_t digestSize) override override override {throw NotImplemented("PK_MessageAccumulator: TruncatedFinal() should not be called");} }; diff --git a/src/cryptopp/smartptr.h b/src/cryptopp/smartptr.h index 6b4040e9..c7bfd6fe 100644 --- a/src/cryptopp/smartptr.h +++ b/src/cryptopp/smartptr.h @@ -202,7 +202,7 @@ template class vector_member_ptrs size_t size() const {return this->m_size;} void resize(size_t newSize) { - member_ptr *newPtr = new member_ptr[newSize]; + autober_ptr[newSize]; for (size_t i=0; im_size && im_ptr[i].release()); delete [] this->m_ptr; diff --git a/src/db.cpp b/src/db.cpp index 0587f974..5161704f 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -212,7 +212,7 @@ bool CDB::Rewrite(const string& strFile) string strFileRes = strFile + ".rewrite"; { // surround usage of db with extra {} CDB db(strFile.c_str(), "r"); - Db* pdbCopy = new Db(&dbenv, 0); + auto* pdbCopy = new Db(&dbenv, 0); int ret = pdbCopy->open(NULL, // Txn pointer strFileRes.c_str(), // Filename @@ -557,7 +557,7 @@ CBlockIndex static * InsertBlockIndex(uint256 hash) return (*mi).second; // Create new - CBlockIndex* pindexNew = new CBlockIndex(); + auto* pindexNew = new CBlockIndex(); if (!pindexNew) throw runtime_error("LoadBlockIndex() : new CBlockIndex failed"); mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first; diff --git a/src/gamedb.cpp b/src/gamedb.cpp index e34d0268..b0c1a161 100644 --- a/src/gamedb.cpp +++ b/src/gamedb.cpp @@ -74,7 +74,7 @@ class GameStepValidator GameStepValidator(DatabaseSet& dbset, CBlockIndex *pindex) : fOwnState(true), fOwnDb(false), pdbset(&dbset) { - GameState *newState = new GameState; + auto *newState = new GameState; if (!GetGameState (dbset, pindex, *newState)) { delete newState; diff --git a/src/huntercoin.cpp b/src/huntercoin.cpp index 9a733d6b..cafccac4 100644 --- a/src/huntercoin.cpp +++ b/src/huntercoin.cpp @@ -69,47 +69,47 @@ uint256 hashHuntercoinGenesisBlock[2] = { class CHuntercoinHooks : public CHooks { public: - virtual bool IsStandard(const CScript& scriptPubKey); - virtual void AddToWallet(CWalletTx& tx); - virtual bool CheckTransaction(const CTransaction& tx); - virtual bool ConnectInputs(DatabaseSet& dbset, const CTestPool& testPool, + bool IsStandard(const CScript& scriptPubKey) override; + void AddToWallet(CWalletTx& tx) override; + bool CheckTransaction(const CTransaction& tx) override; + bool ConnectInputs(DatabaseSet& dbset, const CTestPool& testPool, const CTransaction& tx, const std::vector& vTxoPrev, const CBlockIndex* pindexBlock, const CDiskTxPos& txPos, bool fBlock, - bool fMiner); - virtual bool DisconnectInputs (DatabaseSet& dbset, + bool fMiner) override; + bool DisconnectInputs (DatabaseSet& dbset, const CTransaction& tx, - CBlockIndex* pindexBlock); - virtual bool ConnectBlock (CBlock& block, DatabaseSet& txdb, + CBlockIndex* pindexBlock) override; + bool ConnectBlock (CBlock& block, DatabaseSet& txdb, CBlockIndex* pindex, int64 &nFees, - unsigned int nPosAfterTx); - virtual void NewBlockAdded (); - virtual bool DisconnectBlock (CBlock& block, DatabaseSet& txdb, - CBlockIndex* pindex); - virtual bool ExtractAddress(const CScript& script, string& address); - virtual bool GenesisBlock(CBlock& block); - virtual bool Lockin(int nHeight, uint256 hash); - virtual int LockinHeight(); + unsigned int nPosAfterTx) override; + void NewBlockAdded () override; + bool DisconnectBlock (CBlock& block, DatabaseSet& txdb, + CBlockIndex* pindex) override; + bool ExtractAddress(const CScript& script, string& address) override; + bool GenesisBlock(CBlock& block) override; + bool Lockin(int nHeight, uint256 hash) override; + int LockinHeight() override; virtual string IrcPrefix(); - virtual bool AcceptToMemoryPool (DatabaseSet& dbset, - const CTransaction& tx); - virtual void RemoveFromMemoryPool (const CTransaction& tx); + bool AcceptToMemoryPool (DatabaseSet& dbset, + const CTransaction& tx) override; + void RemoveFromMemoryPool (const CTransaction& tx) override; - virtual void MessageStart(char* pchMessageStart) + void MessageStart(char* pchMessageStart) override { // Make the message start different pchMessageStart[3] = 0xfe; } - virtual bool IsMine(const CTransaction& tx); - virtual bool IsMine(const CTransaction& tx, const CTxOut& txout, bool ignore_name_new = false); + bool IsMine(const CTransaction& tx) override; + bool IsMine(const CTransaction& tx, const CTxOut& txout, bool ignore_name_new = false) override; - virtual void GetMinFee(int64 &nMinFee, int64 &nBaseFee, const CTransaction &tx, + void GetMinFee(int64 &nMinFee, int64 &nBaseFee, const CTransaction &tx, unsigned int nBlockSize, bool fAllowFree, bool fForRelay, - unsigned int nBytes, unsigned int nNewBlockSize); + unsigned int nBytes, unsigned int nNewBlockSize) override; - virtual bool CheckFees (const CTransaction& tx, int64 nFees); + bool CheckFees (const CTransaction& tx, int64 nFees) override; string GetAlertPubkey1() { diff --git a/src/json/json_spirit_reader_template.h b/src/json/json_spirit_reader_template.h index 65b3c7d6..8c12a6d3 100644 --- a/src/json/json_spirit_reader_template.h +++ b/src/json/json_spirit_reader_template.h @@ -526,7 +526,7 @@ namespace json_spirit mtx_parser.lock(); Semantic_actions< Value_type, Iter_type > semantic_actions( value ); - Json_grammer< Value_type, Iter_type > *jg = new Json_grammer< Value_type, Iter_type>( semantic_actions ); + auto); const spirit_namespace::parse_info< Iter_type > info = spirit_namespace::parse( begin, end, *jg, spirit_namespace::space_p ); diff --git a/src/main.cpp b/src/main.cpp index af129f35..99b1cac2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1658,7 +1658,7 @@ bool CBlock::AddToBlockIndex(unsigned int nFile, unsigned int nBlockPos) return error("AddToBlockIndex() : %s already exists", hash.ToString().substr(0,20).c_str()); // Construct new block index object - CBlockIndex* pindexNew = new CBlockIndex(nFile, nBlockPos, *this); + auto* pindexNew = new CBlockIndex(nFile, nBlockPos, *this); if (!pindexNew) return error("AddToBlockIndex() : new CBlockIndex failed"); map::iterator mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first; @@ -1950,7 +1950,7 @@ bool ProcessBlock(CNode* pfrom, CBlock* pblock) if (!mapBlockIndex.count(pblock->hashPrevBlock)) { printf("ProcessBlock: ORPHAN BLOCK, prev=%s\n", pblock->hashPrevBlock.ToString().substr(0,20).c_str()); - CBlock* pblock2 = new CBlock(*pblock); + auto* pblock2 = new CBlock(*pblock); mapOrphanBlocks.insert(make_pair(hash, pblock2)); mapOrphanBlocksByPrev.insert(make_pair(pblock2->hashPrevBlock, pblock2)); diff --git a/src/net.cpp b/src/net.cpp index f25e82b0..f45ec606 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -675,7 +675,7 @@ CNode* ConnectNode(CAddress addrConnect, int64 nTimeout) #endif // Add node - CNode* pnode = new CNode(hSocket, addrConnect, false); + auto* pnode = new CNode(hSocket, addrConnect, false); if (nTimeout != 0) pnode->AddRef(nTimeout); else @@ -901,7 +901,7 @@ void ThreadSocketHandler2(void* parg) else { printf("accepted connection %s\n", addr.ToString().c_str()); - CNode* pnode = new CNode(hSocket, addr, true); + auto* pnode = new CNode(hSocket, addr, true); pnode->AddRef(); CRITICAL_BLOCK(cs_vNodes) vNodes.push_back(pnode); diff --git a/src/wallet.h b/src/wallet.h index cdd6f609..97c5adb7 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -82,9 +82,9 @@ class CWallet : public CKeyStore std::vector vchDefaultKey; // Adds a key to the store, and saves it to disk. - bool AddKey(const CKey& key); + bool AddKey(const CKey& key) override override override override override override override override override override override override override override override override override; // Adds a watching address to the store, saves it to disk. - bool AddAddress(const uint160& hash160); + bool AddAddress(const uint160& hash160) override override override override override override override override override override override override override override override override override; // Adds a key to the store, without saving it to disk (used by LoadWallet) bool LoadKey(const CKey& key) { return CKeyStore::AddKey(key); } // Adds a watching address to the store, without saving it to disk (used by LoadWallet) @@ -259,7 +259,7 @@ class CWallet : public CKeyStore bool EncryptWallet(const SecureString& strWalletPassphrase); // Adds an encrypted key to the store, and saves it to disk. - bool AddCryptedKey(const std::vector &vchPubKey, const std::vector &vchCryptedSecret); + bool AddCryptedKey(const std::vector &vchPubKey, const std::vector &vchCryptedSecret) override override override override override override override override override override override override override override; // Adds an encrypted key to the store, without saving it to disk (used by LoadWallet) bool LoadCryptedKey(const std::vector &vchPubKey, const std::vector &vchCryptedSecret) { /*SetMinVersion(FEATURE_WALLETCRYPT);*/ return CKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret); }