diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -315,6 +315,7 @@ AX_CHECK_COMPILE_FLAG([-Wformat],[CXXFLAGS="$CXXFLAGS -Wformat"],,[[$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([-Wshadow],[CXXFLAGS="$CXXFLAGS -Wshadow"],,[[$CXXFLAG_WERROR]]) ## Some compilers (gcc) ignore unknown -Wno-* options, but warn about all ## unknown options if any other warning is produced. Test the -Wfoo case, and diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -33,6 +33,7 @@ -Wformat-security -Wcast-align -Wunused-parameter + -Wshadow ) option(EXTRA_WARNINGS "Enable extra warnings" OFF) diff --git a/src/arith_uint256.cpp b/src/arith_uint256.cpp --- a/src/arith_uint256.cpp +++ b/src/arith_uint256.cpp @@ -151,8 +151,10 @@ template unsigned int base_uint::bits() const { for (int pos = WIDTH - 1; pos >= 0; pos--) { if (pn[pos]) { - for (int bits = 31; bits > 0; bits--) { - if (pn[pos] & 1 << bits) return 32 * pos + bits + 1; + for (int nbits = 31; nbits > 0; nbits--) { + if (pn[pos] & 1 << nbits) { + return 32 * pos + nbits + 1; + } } return 32 * pos + 1; } diff --git a/src/bench/lockedpool.cpp b/src/bench/lockedpool.cpp --- a/src/bench/lockedpool.cpp +++ b/src/bench/lockedpool.cpp @@ -13,7 +13,7 @@ #define BITER 5000 #define MSIZE 2048 -static void LockedPool(benchmark::State &state) { +static void BenchLockedPool(benchmark::State &state) { void *synth_base = reinterpret_cast(0x08000000); const size_t synth_size = 1024 * 1024; Arena b(synth_base, synth_size, 16); @@ -41,4 +41,4 @@ addr.clear(); } -BENCHMARK(LockedPool); +BENCHMARK(BenchLockedPool); diff --git a/src/chain.h b/src/chain.h --- a/src/chain.h +++ b/src/chain.h @@ -277,9 +277,9 @@ template inline void SerializationOp(Stream &s, Operation ser_action) { - int version = s.GetVersion(); + int _nVersion = s.GetVersion(); if (!(s.GetType() & SER_GETHASH)) { - READWRITE(VARINT(version)); + READWRITE(VARINT(_nVersion)); } READWRITE(VARINT(nHeight)); diff --git a/src/script/script.h b/src/script/script.h --- a/src/script/script.h +++ b/src/script/script.h @@ -476,14 +476,14 @@ insert(end(), uint8_t(b.size())); } else if (b.size() <= 0xffff) { insert(end(), OP_PUSHDATA2); - uint8_t data[2]; - WriteLE16(data, b.size()); - insert(end(), data, data + sizeof(data)); + uint8_t _data[2]; + WriteLE16(_data, b.size()); + insert(end(), _data, _data + sizeof(_data)); } else { insert(end(), OP_PUSHDATA4); - uint8_t data[4]; - WriteLE32(data, b.size()); - insert(end(), data, data + sizeof(data)); + uint8_t _data[4]; + WriteLE32(_data, b.size()); + insert(end(), _data, _data + sizeof(_data)); } insert(end(), b.begin(), b.end()); return *this; diff --git a/src/script/script.cpp b/src/script/script.cpp --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -394,10 +394,10 @@ // get the last item that the scriptSig // pushes onto the stack: const_iterator pc = scriptSig.begin(); - std::vector data; + std::vector vData; while (pc < scriptSig.end()) { opcodetype opcode; - if (!scriptSig.GetOp(pc, opcode, data)) { + if (!scriptSig.GetOp(pc, opcode, vData)) { return 0; } if (opcode > OP_16) { @@ -406,7 +406,7 @@ } /// ... and return its opcount: - CScript subscript(data.begin(), data.end()); + CScript subscript(vData.begin(), vData.end()); return subscript.GetSigOpCount(flags, true); } diff --git a/src/streams.h b/src/streams.h --- a/src/streams.h +++ b/src/streams.h @@ -556,13 +556,13 @@ unsigned int nAvail = vchBuf.size() - (nSrcPos - nReadPos) - nRewind; if (nAvail < readNow) readNow = nAvail; if (readNow == 0) return false; - size_t read = fread((void *)&vchBuf[pos], 1, readNow, src); - if (read == 0) { + size_t nBytes = fread((void *)&vchBuf[pos], 1, readNow, src); + if (nBytes == 0) { throw std::ios_base::failure( feof(src) ? "CBufferedFile::Fill: end of file" : "CBufferedFile::Fill: fread failed"); } else { - nSrcPos += read; + nSrcPos += nBytes; return true; } } diff --git a/src/support/lockedpool.cpp b/src/support/lockedpool.cpp --- a/src/support/lockedpool.cpp +++ b/src/support/lockedpool.cpp @@ -348,8 +348,8 @@ // Implementation: LockedPoolManager // LockedPoolManager::LockedPoolManager( - std::unique_ptr allocator) - : LockedPool(std::move(allocator), &LockedPoolManager::LockingFailed) {} + std::unique_ptr allocator_in) + : LockedPool(std::move(allocator_in), &LockedPoolManager::LockingFailed) {} bool LockedPoolManager::LockingFailed() { // TODO: log something but how? without including util.h diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp --- a/src/test/coins_tests.cpp +++ b/src/test/coins_tests.cpp @@ -76,7 +76,7 @@ class CCoinsViewCacheTest : public CCoinsViewCache { public: - CCoinsViewCacheTest(CCoinsView *base) : CCoinsViewCache(base) {} + CCoinsViewCacheTest(CCoinsView *_base) : CCoinsViewCache(_base) {} void SelfTest() const { // Manually recompute the dynamic usage of the whole data, and compare diff --git a/src/timedata.h b/src/timedata.h --- a/src/timedata.h +++ b/src/timedata.h @@ -25,8 +25,8 @@ unsigned int nSize; public: - CMedianFilter(unsigned int size, T initial_value) : nSize(size) { - vValues.reserve(size); + CMedianFilter(unsigned int _size, T initial_value) : nSize(_size) { + vValues.reserve(_size); vValues.push_back(initial_value); vSorted = vValues; } @@ -43,15 +43,15 @@ } T median() const { - int size = vSorted.size(); - assert(size > 0); - - if (size & 1) { + int vSortedSize = vSorted.size(); + assert(vSortedSize > 0); + if (vSortedSize & 1) { // Odd number of elements - return vSorted[size / 2]; + return vSorted[vSortedSize / 2]; } else { // Even number of elements - return (vSorted[size / 2 - 1] + vSorted[size / 2]) / 2; + return (vSorted[vSortedSize / 2 - 1] + vSorted[vSortedSize / 2]) / + 2; } }