Merge #8808: Do not shadow variables (gcc set)

ad1ae7a Check and enable -Wshadow by default. (Pavel Janík)
9de90bb Do not shadow variables (gcc set) (Pavel Janík)

Tree-SHA512: 9517feb423dc8ddd63896016b25324673bfbe0bffa97f22996f59d7a3fcbdc2ebf2e43ac02bc067546f54e293e9b2f2514be145f867321e9031f895c063d9fb8
This commit is contained in:
Wladimir J. van der Laan 2017-03-03 15:48:18 +01:00
commit 75d012e8c7
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
15 changed files with 46 additions and 45 deletions

View File

@ -227,6 +227,7 @@ if test "x$CXXFLAGS_overridden" = "xno"; then
AX_CHECK_COMPILE_FLAG([-Wformat],[CXXFLAGS="$CXXFLAGS -Wformat"],,[[$CXXFLAG_WERROR]]) AX_CHECK_COMPILE_FLAG([-Wformat],[CXXFLAGS="$CXXFLAGS -Wformat"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Wvla],[CXXFLAGS="$CXXFLAGS -Wvla"],,[[$CXXFLAG_WERROR]]) AX_CHECK_COMPILE_FLAG([-Wvla],[CXXFLAGS="$CXXFLAGS -Wvla"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Wformat-security],[CXXFLAGS="$CXXFLAGS -Wformat-security"],,[[$CXXFLAG_WERROR]]) AX_CHECK_COMPILE_FLAG([-Wformat-security],[CXXFLAGS="$CXXFLAGS -Wformat-security"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Wshadow],[CXXFLAGS="$CXXFLAGS -Wshadow"],,[[$CXXFLAG_WERROR]])
## Some compilers (gcc) ignore unknown -Wno-* options, but warn about all ## Some compilers (gcc) ignore unknown -Wno-* options, but warn about all
## unknown options if any other warning is produced. Test the -Wfoo case, and ## unknown options if any other warning is produced. Test the -Wfoo case, and

View File

@ -173,9 +173,9 @@ unsigned int base_uint<BITS>::bits() const
{ {
for (int pos = WIDTH - 1; pos >= 0; pos--) { for (int pos = WIDTH - 1; pos >= 0; pos--) {
if (pn[pos]) { if (pn[pos]) {
for (int bits = 31; bits > 0; bits--) { for (int nbits = 31; nbits > 0; nbits--) {
if (pn[pos] & 1 << bits) if (pn[pos] & 1 << nbits)
return 32 * pos + bits + 1; return 32 * pos + nbits + 1;
} }
return 32 * pos + 1; return 32 * pos + 1;
} }

View File

@ -13,7 +13,7 @@
#define BITER 5000 #define BITER 5000
#define MSIZE 2048 #define MSIZE 2048
static void LockedPool(benchmark::State& state) static void BenchLockedPool(benchmark::State& state)
{ {
void *synth_base = reinterpret_cast<void*>(0x08000000); void *synth_base = reinterpret_cast<void*>(0x08000000);
const size_t synth_size = 1024*1024; const size_t synth_size = 1024*1024;
@ -43,5 +43,5 @@ static void LockedPool(benchmark::State& state)
addr.clear(); addr.clear();
} }
BENCHMARK(LockedPool); BENCHMARK(BenchLockedPool);

View File

@ -367,9 +367,9 @@ public:
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) { inline void SerializationOp(Stream& s, Operation ser_action) {
int nVersion = s.GetVersion(); int _nVersion = s.GetVersion();
if (!(s.GetType() & SER_GETHASH)) if (!(s.GetType() & SER_GETHASH))
READWRITE(VARINT(nVersion)); READWRITE(VARINT(_nVersion));
READWRITE(VARINT(nHeight)); READWRITE(VARINT(nHeight));
READWRITE(VARINT(nStatus)); READWRITE(VARINT(nStatus));

View File

@ -171,7 +171,7 @@ private:
const CTransaction txTo; const CTransaction txTo;
public: public:
MutableTransactionSignatureChecker(const CMutableTransaction* txToIn, unsigned int nInIn, const CAmount& amount) : TransactionSignatureChecker(&txTo, nInIn, amount), txTo(*txToIn) {} MutableTransactionSignatureChecker(const CMutableTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn) : TransactionSignatureChecker(&txTo, nInIn, amountIn), txTo(*txToIn) {}
}; };
bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker, SigVersion sigversion, ScriptError* error = NULL); bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker, SigVersion sigversion, ScriptError* error = NULL);

View File

@ -186,18 +186,18 @@ unsigned int CScript::GetSigOpCount(const CScript& scriptSig) const
// get the last item that the scriptSig // get the last item that the scriptSig
// pushes onto the stack: // pushes onto the stack:
const_iterator pc = scriptSig.begin(); const_iterator pc = scriptSig.begin();
vector<unsigned char> data; vector<unsigned char> vData;
while (pc < scriptSig.end()) while (pc < scriptSig.end())
{ {
opcodetype opcode; opcodetype opcode;
if (!scriptSig.GetOp(pc, opcode, data)) if (!scriptSig.GetOp(pc, opcode, vData))
return 0; return 0;
if (opcode > OP_16) if (opcode > OP_16)
return 0; return 0;
} }
/// ... and return its opcount: /// ... and return its opcount:
CScript subscript(data.begin(), data.end()); CScript subscript(vData.begin(), vData.end());
return subscript.GetSigOpCount(true); return subscript.GetSigOpCount(true);
} }

View File

@ -448,16 +448,16 @@ public:
else if (b.size() <= 0xffff) else if (b.size() <= 0xffff)
{ {
insert(end(), OP_PUSHDATA2); insert(end(), OP_PUSHDATA2);
uint8_t data[2]; uint8_t _data[2];
WriteLE16(data, b.size()); WriteLE16(_data, b.size());
insert(end(), data, data + sizeof(data)); insert(end(), _data, _data + sizeof(_data));
} }
else else
{ {
insert(end(), OP_PUSHDATA4); insert(end(), OP_PUSHDATA4);
uint8_t data[4]; uint8_t _data[4];
WriteLE32(data, b.size()); WriteLE32(_data, b.size());
insert(end(), data, data + sizeof(data)); insert(end(), _data, _data + sizeof(_data));
} }
insert(end(), b.begin(), b.end()); insert(end(), b.begin(), b.end());
return *this; return *this;

View File

@ -25,7 +25,7 @@ private:
bool store; bool store;
public: public:
CachingTransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CAmount& amount, bool storeIn, PrecomputedTransactionData& txdataIn) : TransactionSignatureChecker(txToIn, nInIn, amount, txdataIn), store(storeIn) {} CachingTransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, bool storeIn, PrecomputedTransactionData& txdataIn) : TransactionSignatureChecker(txToIn, nInIn, amountIn, txdataIn), store(storeIn) {}
bool VerifySignature(const std::vector<unsigned char>& vchSig, const CPubKey& vchPubKey, const uint256& sighash) const; bool VerifySignature(const std::vector<unsigned char>& vchSig, const CPubKey& vchPubKey, const uint256& sighash) const;
}; };

View File

@ -48,7 +48,7 @@ class MutableTransactionSignatureCreator : public TransactionSignatureCreator {
CTransaction tx; CTransaction tx;
public: public:
MutableTransactionSignatureCreator(const CKeyStore* keystoreIn, const CMutableTransaction* txToIn, unsigned int nInIn, const CAmount& amount, int nHashTypeIn) : TransactionSignatureCreator(keystoreIn, &tx, nInIn, amount, nHashTypeIn), tx(*txToIn) {} MutableTransactionSignatureCreator(const CKeyStore* keystoreIn, const CMutableTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn) : TransactionSignatureCreator(keystoreIn, &tx, nInIn, amountIn, nHashTypeIn), tx(*txToIn) {}
}; };
/** A signature creator that just produces 72-byte empty signatures. */ /** A signature creator that just produces 72-byte empty signatures. */

View File

@ -584,11 +584,11 @@ protected:
readNow = nAvail; readNow = nAvail;
if (readNow == 0) if (readNow == 0)
return false; return false;
size_t read = fread((void*)&vchBuf[pos], 1, readNow, src); size_t nBytes = fread((void*)&vchBuf[pos], 1, readNow, src);
if (read == 0) { if (nBytes == 0) {
throw std::ios_base::failure(feof(src) ? "CBufferedFile::Fill: end of file" : "CBufferedFile::Fill: fread failed"); throw std::ios_base::failure(feof(src) ? "CBufferedFile::Fill: end of file" : "CBufferedFile::Fill: fread failed");
} else { } else {
nSrcPos += read; nSrcPos += nBytes;
return true; return true;
} }
} }

View File

@ -357,8 +357,8 @@ LockedPool::LockedPageArena::~LockedPageArena()
/*******************************************************************************/ /*******************************************************************************/
// Implementation: LockedPoolManager // Implementation: LockedPoolManager
// //
LockedPoolManager::LockedPoolManager(std::unique_ptr<LockedPageAllocator> allocator): LockedPoolManager::LockedPoolManager(std::unique_ptr<LockedPageAllocator> allocator_in):
LockedPool(std::move(allocator), &LockedPoolManager::LockingFailed) LockedPool(std::move(allocator_in), &LockedPoolManager::LockingFailed)
{ {
} }

View File

@ -72,7 +72,7 @@ public:
class CCoinsViewCacheTest : public CCoinsViewCache class CCoinsViewCacheTest : public CCoinsViewCache
{ {
public: public:
CCoinsViewCacheTest(CCoinsView* base) : CCoinsViewCache(base) {} CCoinsViewCacheTest(CCoinsView* _base) : CCoinsViewCache(_base) {}
void SelfTest() const void SelfTest() const
{ {

View File

@ -27,9 +27,9 @@ private:
unsigned int nSize; unsigned int nSize;
public: public:
CMedianFilter(unsigned int size, T initial_value) : nSize(size) CMedianFilter(unsigned int _size, T initial_value) : nSize(_size)
{ {
vValues.reserve(size); vValues.reserve(_size);
vValues.push_back(initial_value); vValues.push_back(initial_value);
vSorted = vValues; vSorted = vValues;
} }
@ -48,14 +48,14 @@ public:
T median() const T median() const
{ {
int size = vSorted.size(); int vSortedSize = vSorted.size();
assert(size > 0); assert(vSortedSize > 0);
if (size & 1) // Odd number of elements if (vSortedSize & 1) // Odd number of elements
{ {
return vSorted[size / 2]; return vSorted[vSortedSize / 2];
} else // Even number of elements } else // Even number of elements
{ {
return (vSorted[size / 2 - 1] + vSorted[size / 2]) / 2; return (vSorted[vSortedSize / 2 - 1] + vSorted[vSortedSize / 2]) / 2;
} }
} }

View File

@ -296,7 +296,7 @@ bool CWallet::LoadWatchOnly(const CScript &dest)
bool CWallet::Unlock(const SecureString& strWalletPassphrase) bool CWallet::Unlock(const SecureString& strWalletPassphrase)
{ {
CCrypter crypter; CCrypter crypter;
CKeyingMaterial vMasterKey; CKeyingMaterial _vMasterKey;
{ {
LOCK(cs_wallet); LOCK(cs_wallet);
@ -304,9 +304,9 @@ bool CWallet::Unlock(const SecureString& strWalletPassphrase)
{ {
if(!crypter.SetKeyFromPassphrase(strWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod)) if(!crypter.SetKeyFromPassphrase(strWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
return false; return false;
if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, vMasterKey)) if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, _vMasterKey))
continue; // try another master key continue; // try another master key
if (CCryptoKeyStore::Unlock(vMasterKey)) if (CCryptoKeyStore::Unlock(_vMasterKey))
return true; return true;
} }
} }
@ -322,14 +322,14 @@ bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase,
Lock(); Lock();
CCrypter crypter; CCrypter crypter;
CKeyingMaterial vMasterKey; CKeyingMaterial _vMasterKey;
BOOST_FOREACH(MasterKeyMap::value_type& pMasterKey, mapMasterKeys) BOOST_FOREACH(MasterKeyMap::value_type& pMasterKey, mapMasterKeys)
{ {
if(!crypter.SetKeyFromPassphrase(strOldWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod)) if(!crypter.SetKeyFromPassphrase(strOldWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
return false; return false;
if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, vMasterKey)) if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, _vMasterKey))
return false; return false;
if (CCryptoKeyStore::Unlock(vMasterKey)) if (CCryptoKeyStore::Unlock(_vMasterKey))
{ {
int64_t nStartTime = GetTimeMillis(); int64_t nStartTime = GetTimeMillis();
crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod); crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod);
@ -346,7 +346,7 @@ bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase,
if (!crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod)) if (!crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
return false; return false;
if (!crypter.Encrypt(vMasterKey, pMasterKey.second.vchCryptedKey)) if (!crypter.Encrypt(_vMasterKey, pMasterKey.second.vchCryptedKey))
return false; return false;
CWalletDB(strWalletFile).WriteMasterKey(pMasterKey.first, pMasterKey.second); CWalletDB(strWalletFile).WriteMasterKey(pMasterKey.first, pMasterKey.second);
if (fWasLocked) if (fWasLocked)
@ -584,10 +584,10 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
if (IsCrypted()) if (IsCrypted())
return false; return false;
CKeyingMaterial vMasterKey; CKeyingMaterial _vMasterKey;
vMasterKey.resize(WALLET_CRYPTO_KEY_SIZE); _vMasterKey.resize(WALLET_CRYPTO_KEY_SIZE);
GetStrongRandBytes(&vMasterKey[0], WALLET_CRYPTO_KEY_SIZE); GetStrongRandBytes(&_vMasterKey[0], WALLET_CRYPTO_KEY_SIZE);
CMasterKey kMasterKey; CMasterKey kMasterKey;
@ -610,7 +610,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
if (!crypter.SetKeyFromPassphrase(strWalletPassphrase, kMasterKey.vchSalt, kMasterKey.nDeriveIterations, kMasterKey.nDerivationMethod)) if (!crypter.SetKeyFromPassphrase(strWalletPassphrase, kMasterKey.vchSalt, kMasterKey.nDeriveIterations, kMasterKey.nDerivationMethod))
return false; return false;
if (!crypter.Encrypt(vMasterKey, kMasterKey.vchCryptedKey)) if (!crypter.Encrypt(_vMasterKey, kMasterKey.vchCryptedKey))
return false; return false;
{ {
@ -628,7 +628,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
pwalletdbEncryption->WriteMasterKey(nMasterKeyMaxID, kMasterKey); pwalletdbEncryption->WriteMasterKey(nMasterKeyMaxID, kMasterKey);
} }
if (!EncryptKeys(vMasterKey)) if (!EncryptKeys(_vMasterKey))
{ {
if (fFileBacked) { if (fFileBacked) {
pwalletdbEncryption->TxnAbort(); pwalletdbEncryption->TxnAbort();

View File

@ -116,7 +116,7 @@ public:
class CWalletDB : public CDB class CWalletDB : public CDB
{ {
public: public:
CWalletDB(const std::string& strFilename, const char* pszMode = "r+", bool fFlushOnClose = true) : CDB(strFilename, pszMode, fFlushOnClose) CWalletDB(const std::string& strFilename, const char* pszMode = "r+", bool _fFlushOnClose = true) : CDB(strFilename, pszMode, _fFlushOnClose)
{ {
} }