Skip to content

Commit 3d3443b

Browse files
laanwjPastaPastaPasta
authored andcommitted
Merge bitcoin#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
1 parent 053b97c commit 3d3443b

12 files changed

+44
-43
lines changed

configure.ac

+1
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ if test "x$CXXFLAGS_overridden" = "xno"; then
227227
AX_CHECK_COMPILE_FLAG([-Wformat],[CXXFLAGS="$CXXFLAGS -Wformat"],,[[$CXXFLAG_WERROR]])
228228
AX_CHECK_COMPILE_FLAG([-Wvla],[CXXFLAGS="$CXXFLAGS -Wvla"],,[[$CXXFLAG_WERROR]])
229229
AX_CHECK_COMPILE_FLAG([-Wformat-security],[CXXFLAGS="$CXXFLAGS -Wformat-security"],,[[$CXXFLAG_WERROR]])
230+
AX_CHECK_COMPILE_FLAG([-Wshadow],[CXXFLAGS="$CXXFLAGS -Wshadow"],,[[$CXXFLAG_WERROR]])
230231

231232
## Some compilers (gcc) ignore unknown -Wno-* options, but warn about all
232233
## unknown options if any other warning is produced. Test the -Wfoo case, and

src/arith_uint256.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ unsigned int base_uint<BITS>::bits() const
173173
{
174174
for (int pos = WIDTH - 1; pos >= 0; pos--) {
175175
if (pn[pos]) {
176-
for (int bits = 31; bits > 0; bits--) {
177-
if (pn[pos] & 1 << bits)
178-
return 32 * pos + bits + 1;
176+
for (int nbits = 31; nbits > 0; nbits--) {
177+
if (pn[pos] & 1 << nbits)
178+
return 32 * pos + nbits + 1;
179179
}
180180
return 32 * pos + 1;
181181
}

src/bench/lockedpool.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#define BITER 5000
1414
#define MSIZE 2048
1515

16-
static void LockedPool(benchmark::State& state)
16+
static void BenchLockedPool(benchmark::State& state)
1717
{
1818
void *synth_base = reinterpret_cast<void*>(0x08000000);
1919
const size_t synth_size = 1024*1024;
@@ -43,5 +43,5 @@ static void LockedPool(benchmark::State& state)
4343
addr.clear();
4444
}
4545

46-
BENCHMARK(LockedPool);
46+
BENCHMARK(BenchLockedPool);
4747

src/chain.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,9 @@ class CDiskBlockIndex : public CBlockIndex
382382

383383
template <typename Stream, typename Operation>
384384
inline void SerializationOp(Stream& s, Operation ser_action) {
385-
int nVersion = s.GetVersion();
385+
int _nVersion = s.GetVersion();
386386
if (!(s.GetType() & SER_GETHASH))
387-
READWRITE(VARINT(nVersion));
387+
READWRITE(VARINT(_nVersion));
388388

389389
READWRITE(VARINT(nHeight));
390390
READWRITE(VARINT(nStatus));

src/script/script.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -183,18 +183,18 @@ unsigned int CScript::GetSigOpCount(const CScript& scriptSig) const
183183
// get the last item that the scriptSig
184184
// pushes onto the stack:
185185
const_iterator pc = scriptSig.begin();
186-
std::vector<unsigned char> data;
186+
std::vector<unsigned char> vData;
187187
while (pc < scriptSig.end())
188188
{
189189
opcodetype opcode;
190-
if (!scriptSig.GetOp(pc, opcode, data))
190+
if (!scriptSig.GetOp(pc, opcode, vData))
191191
return 0;
192192
if (opcode > OP_16)
193193
return 0;
194194
}
195195

196196
/// ... and return its opcount:
197-
CScript subscript(data.begin(), data.end());
197+
CScript subscript(vData.begin(), vData.end());
198198
return subscript.GetSigOpCount(true);
199199
}
200200

src/script/script.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -448,16 +448,16 @@ class CScript : public CScriptBase
448448
else if (b.size() <= 0xffff)
449449
{
450450
insert(end(), OP_PUSHDATA2);
451-
uint8_t data[2];
452-
WriteLE16(data, b.size());
453-
insert(end(), data, data + sizeof(data));
451+
uint8_t _data[2];
452+
WriteLE16(_data, b.size());
453+
insert(end(), _data, _data + sizeof(_data));
454454
}
455455
else
456456
{
457457
insert(end(), OP_PUSHDATA4);
458-
uint8_t data[4];
459-
WriteLE32(data, b.size());
460-
insert(end(), data, data + sizeof(data));
458+
uint8_t _data[4];
459+
WriteLE32(_data, b.size());
460+
insert(end(), _data, _data + sizeof(_data));
461461
}
462462
insert(end(), b.begin(), b.end());
463463
return *this;

src/streams.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -545,11 +545,11 @@ class CBufferedFile
545545
readNow = nAvail;
546546
if (readNow == 0)
547547
return false;
548-
size_t read = fread((void*)&vchBuf[pos], 1, readNow, src);
549-
if (read == 0) {
548+
size_t nBytes = fread((void*)&vchBuf[pos], 1, readNow, src);
549+
if (nBytes == 0) {
550550
throw std::ios_base::failure(feof(src) ? "CBufferedFile::Fill: end of file" : "CBufferedFile::Fill: fread failed");
551551
} else {
552-
nSrcPos += read;
552+
nSrcPos += nBytes;
553553
return true;
554554
}
555555
}

src/support/lockedpool.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,8 @@ LockedPool::LockedPageArena::~LockedPageArena()
357357
/*******************************************************************************/
358358
// Implementation: LockedPoolManager
359359
//
360-
LockedPoolManager::LockedPoolManager(std::unique_ptr<LockedPageAllocator> allocator):
361-
LockedPool(std::move(allocator), &LockedPoolManager::LockingFailed)
360+
LockedPoolManager::LockedPoolManager(std::unique_ptr<LockedPageAllocator> allocator_in):
361+
LockedPool(std::move(allocator_in), &LockedPoolManager::LockingFailed)
362362
{
363363
}
364364

src/test/coins_tests.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class CCoinsViewTest : public CCoinsView
7575
class CCoinsViewCacheTest : public CCoinsViewCache
7676
{
7777
public:
78-
CCoinsViewCacheTest(CCoinsView* base) : CCoinsViewCache(base) {}
78+
CCoinsViewCacheTest(CCoinsView* _base) : CCoinsViewCache(_base) {}
7979

8080
void SelfTest() const
8181
{

src/timedata.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class CMedianFilter
2727
unsigned int nSize;
2828

2929
public:
30-
CMedianFilter(unsigned int size, T initial_value) : nSize(size)
30+
CMedianFilter(unsigned int _size, T initial_value) : nSize(_size)
3131
{
32-
vValues.reserve(size);
32+
vValues.reserve(_size);
3333
vValues.push_back(initial_value);
3434
vSorted = vValues;
3535
}
@@ -48,14 +48,14 @@ class CMedianFilter
4848

4949
T median() const
5050
{
51-
int size = vSorted.size();
52-
assert(size > 0);
53-
if (size & 1) // Odd number of elements
51+
int vSortedSize = vSorted.size();
52+
assert(vSortedSize > 0);
53+
if (vSortedSize & 1) // Odd number of elements
5454
{
55-
return vSorted[size / 2];
55+
return vSorted[vSortedSize / 2];
5656
} else // Even number of elements
5757
{
58-
return (vSorted[size / 2 - 1] + vSorted[size / 2]) / 2;
58+
return (vSorted[vSortedSize / 2 - 1] + vSorted[vSortedSize / 2]) / 2;
5959
}
6060
}
6161

src/wallet/wallet.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -441,17 +441,17 @@ bool CWallet::Unlock(const SecureString& strWalletPassphrase, bool fForMixingOnl
441441
}
442442

443443
CCrypter crypter;
444-
CKeyingMaterial vMasterKey;
444+
CKeyingMaterial _vMasterKey;
445445

446446
{
447447
LOCK(cs_wallet);
448448
BOOST_FOREACH(const MasterKeyMap::value_type& pMasterKey, mapMasterKeys)
449449
{
450450
if (!crypter.SetKeyFromPassphrase(strWalletPassphraseFinal, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
451451
return false;
452-
if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, vMasterKey))
452+
if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, _vMasterKey))
453453
continue; // try another master key
454-
if (CCryptoKeyStore::Unlock(vMasterKey, fForMixingOnly)) {
454+
if (CCryptoKeyStore::Unlock(_vMasterKey, fForMixingOnly)) {
455455
if(nWalletBackups == -2) {
456456
TopUpKeyPool();
457457
LogPrintf("Keypool replenished, re-initializing automatic backups.\n");
@@ -489,14 +489,14 @@ bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase,
489489
Lock();
490490

491491
CCrypter crypter;
492-
CKeyingMaterial vMasterKey;
492+
CKeyingMaterial _vMasterKey;
493493
BOOST_FOREACH(MasterKeyMap::value_type& pMasterKey, mapMasterKeys)
494494
{
495495
if(!crypter.SetKeyFromPassphrase(strOldWalletPassphraseFinal, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
496496
return false;
497-
if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, vMasterKey))
497+
if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, _vMasterKey))
498498
return false;
499-
if (CCryptoKeyStore::Unlock(vMasterKey))
499+
if (CCryptoKeyStore::Unlock(_vMasterKey))
500500
{
501501
int64_t nStartTime = GetTimeMillis();
502502
crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod);
@@ -513,7 +513,7 @@ bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase,
513513

514514
if (!crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
515515
return false;
516-
if (!crypter.Encrypt(vMasterKey, pMasterKey.second.vchCryptedKey))
516+
if (!crypter.Encrypt(_vMasterKey, pMasterKey.second.vchCryptedKey))
517517
return false;
518518
CWalletDB(strWalletFile).WriteMasterKey(pMasterKey.first, pMasterKey.second);
519519
if (fWasLocked)
@@ -757,10 +757,10 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
757757
if (IsCrypted())
758758
return false;
759759

760-
CKeyingMaterial vMasterKey;
760+
CKeyingMaterial _vMasterKey;
761761

762-
vMasterKey.resize(WALLET_CRYPTO_KEY_SIZE);
763-
GetStrongRandBytes(&vMasterKey[0], WALLET_CRYPTO_KEY_SIZE);
762+
_vMasterKey.resize(WALLET_CRYPTO_KEY_SIZE);
763+
GetStrongRandBytes(&_vMasterKey[0], WALLET_CRYPTO_KEY_SIZE);
764764

765765
CMasterKey kMasterKey;
766766

@@ -783,7 +783,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
783783

784784
if (!crypter.SetKeyFromPassphrase(strWalletPassphrase, kMasterKey.vchSalt, kMasterKey.nDeriveIterations, kMasterKey.nDerivationMethod))
785785
return false;
786-
if (!crypter.Encrypt(vMasterKey, kMasterKey.vchCryptedKey))
786+
if (!crypter.Encrypt(_vMasterKey, kMasterKey.vchCryptedKey))
787787
return false;
788788

789789
{
@@ -805,7 +805,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
805805
CHDChain hdChainCurrent;
806806
GetHDChain(hdChainCurrent);
807807

808-
if (!EncryptKeys(vMasterKey))
808+
if (!EncryptKeys(_vMasterKey))
809809
{
810810
if (fFileBacked) {
811811
pwalletdbEncryption->TxnAbort();
@@ -817,7 +817,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
817817
}
818818

819819
if (!hdChainCurrent.IsNull()) {
820-
assert(EncryptHDChain(vMasterKey));
820+
assert(EncryptHDChain(_vMasterKey));
821821

822822
CHDChain hdChainCrypted;
823823
assert(GetHDChain(hdChainCrypted));

src/wallet/walletdb.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class CKeyMetadata
7777
class CWalletDB : public CDB
7878
{
7979
public:
80-
CWalletDB(const std::string& strFilename, const char* pszMode = "r+", bool fFlushOnClose = true) : CDB(strFilename, pszMode, fFlushOnClose)
80+
CWalletDB(const std::string& strFilename, const char* pszMode = "r+", bool _fFlushOnClose = true) : CDB(strFilename, pszMode, _fFlushOnClose)
8181
{
8282
}
8383

0 commit comments

Comments
 (0)