Skip to content

Commit

Permalink
fix a few more shadowing issues (bitcoin#1210)
Browse files Browse the repository at this point in the history
* Do not shadow  nVersion in CDiskBlockIndex

* Do not shadow proxy or randomize_credentials in netbase.h

* Do not shadow vch in pubkey.h

* Do not shadow page_size in support/pagelocker.h

* Do not shadow amount in MutableTransactionSignatureChecker

* Do not shadow name in stat.h

* Do not shadow addr in net.h

* Do not shadow fpr in graphen_set.h

* Do not shadow fFlushOnClose in walletdb.h

* Do not shadow vMasterKey in wallet.cpp

* Do not shadow amount in TransactionSignatureChecker()

* Do not shadow socket and whitelisted in ListenSocket

* Remove duplicate code in rpc/mining.cpp

Looks like duplicate if statements which were then cut and paste
elsewhere. This resulted in a shadowing warning.

* Do not shadow base in torcontrol.cpp

* Do not shadow name and buffer in test_bitcoin_fuzzy.cp

* Do not shadow ip in CService

* Do not shadow variables in httpserver.cpp
  • Loading branch information
ptschip authored and gandrewstone committed Jul 24, 2018
1 parent 109e851 commit a5c18a0
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 83 deletions.
4 changes: 2 additions & 2 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,9 @@ class CDiskBlockIndex : public CBlockIndex
template <typename Stream, typename Operation>
inline void SerializationOp(Stream &s, Operation ser_action)
{
int nVersion = s.GetVersion();
int _nVersion = s.GetVersion();
if (!(s.GetType() & SER_GETHASH))
READWRITE(VARINT(nVersion, VarIntMode::NONNEGATIVE_SIGNED));
READWRITE(VARINT(_nVersion, VarIntMode::NONNEGATIVE_SIGNED));

READWRITE(VARINT(nHeight, VarIntMode::NONNEGATIVE_SIGNED));
READWRITE(VARINT(nStatus));
Expand Down
4 changes: 2 additions & 2 deletions src/graphene_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ class CGrapheneSet
return 1;

auto fpr = [nReceiverPoolTx, nBlockAndReceiverPoolTx](uint64_t a) {
float fpr = a / float(nReceiverPoolTx - nBlockAndReceiverPoolTx);
float _fpr = a / float(nReceiverPoolTx - nBlockAndReceiverPoolTx);

return fpr < 1.0 ? fpr : FILTER_FPR_MAX;
return _fpr < 1.0 ? _fpr : FILTER_FPR_MAX;
};

auto F = [nBlockTxs, fpr](
Expand Down
16 changes: 8 additions & 8 deletions src/httpserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ static const size_t MAX_HEADERS_SIZE = 8192;
class HTTPWorkItem : public HTTPClosure
{
public:
HTTPWorkItem(std::unique_ptr<HTTPRequest> req, const std::string &path, const HTTPRequestHandler &func)
: req(std::move(req)), path(path), func(func)
HTTPWorkItem(std::unique_ptr<HTTPRequest> _req, const std::string &_path, const HTTPRequestHandler &_func)
: req(std::move(_req)), path(_path), func(_func)
{
}
void operator()() { func(req.get(), path); }
Expand Down Expand Up @@ -91,7 +91,7 @@ class WorkQueue
};

public:
WorkQueue(size_t maxDepth) : running(true), maxDepth(maxDepth), numThreads(0) {}
WorkQueue(size_t _maxDepth) : running(true), maxDepth(_maxDepth), numThreads(0) {}
/** Precondition: worker threads have all stopped
*/
~WorkQueue() {}
Expand Down Expand Up @@ -138,8 +138,8 @@ class WorkQueue
struct HTTPPathHandler
{
HTTPPathHandler() {}
HTTPPathHandler(std::string prefix, bool exactMatch, HTTPRequestHandler handler)
: prefix(prefix), exactMatch(exactMatch), handler(handler)
HTTPPathHandler(std::string _prefix, bool _exactMatch, HTTPRequestHandler _handler)
: prefix(_prefix), exactMatch(_exactMatch), handler(_handler)
{
}
std::string prefix;
Expand Down Expand Up @@ -559,8 +559,8 @@ static void httpevent_callback_fn(evutil_socket_t, short, void *data)
delete self;
}

HTTPEvent::HTTPEvent(struct event_base *base, bool deleteWhenTriggered, const std::function<void(void)> &handler)
: deleteWhenTriggered(deleteWhenTriggered), handler(handler)
HTTPEvent::HTTPEvent(struct event_base *base, bool _deleteWhenTriggered, const std::function<void(void)> &_handler)
: deleteWhenTriggered(_deleteWhenTriggered), handler(_handler)
{
ev = event_new(base, -1, 0, httpevent_callback_fn, this);
assert(ev);
Expand All @@ -573,7 +573,7 @@ void HTTPEvent::trigger(struct timeval *tv)
else
evtimer_add(ev, tv); // trigger after timeval passed
}
HTTPRequest::HTTPRequest(struct evhttp_request *req) : req(req), replySent(false) {}
HTTPRequest::HTTPRequest(struct evhttp_request *_req) : req(_req), replySent(false) {}
HTTPRequest::~HTTPRequest()
{
if (!replySent)
Expand Down
2 changes: 1 addition & 1 deletion src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ struct ListenSocket
{
SOCKET socket;
bool whitelisted;
ListenSocket(SOCKET socket, bool whitelisted) : socket(socket), whitelisted(whitelisted) {}
ListenSocket(SOCKET _socket, bool _whitelisted) : socket(_socket), whitelisted(_whitelisted) {}
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ class CNode
return false;
}

void AddAddressKnown(const CAddress &addr) { addrKnown.insert(addr.GetKey()); }
void AddAddressKnown(const CAddress &_addr) { addrKnown.insert(_addr.GetKey()); }
void PushAddress(const CAddress &_addr, FastRandomContext &insecure_rand)
{
// Known checking here is only to save space from duplicates.
Expand Down
24 changes: 12 additions & 12 deletions src/netaddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,30 +435,30 @@ CService::CService(const struct sockaddr_in6 &addr)

CService::CService(const char *pszIpPort) : port(0)
{
CService ip;
if (Lookup(pszIpPort, ip, 0, false))
*this = ip;
CService _ip;
if (Lookup(pszIpPort, _ip, 0, false))
*this = _ip;
}

CService::CService(const char *pszIpPort, int portDefault) : port(0)
{
CService ip;
if (Lookup(pszIpPort, ip, portDefault, false))
*this = ip;
CService _ip;
if (Lookup(pszIpPort, _ip, portDefault, false))
*this = _ip;
}

CService::CService(const std::string &strIpPort) : port(0)
{
CService ip;
if (Lookup(strIpPort.c_str(), ip, 0, false))
*this = ip;
CService _ip;
if (Lookup(strIpPort.c_str(), _ip, 0, false))
*this = _ip;
}

CService::CService(const std::string &strIpPort, int portDefault) : port(0)
{
CService ip;
if (Lookup(strIpPort.c_str(), ip, portDefault, false))
*this = ip;
CService _ip;
if (Lookup(strIpPort.c_str(), _ip, portDefault, false))
*this = _ip;
}

bool CService::SetSockAddr(const struct sockaddr *paddr)
Expand Down
4 changes: 2 additions & 2 deletions src/netbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class proxyType
{
public:
proxyType() : randomize_credentials(false) {}
proxyType(const CService &proxy, bool randomize_credentials = false)
: proxy(proxy), randomize_credentials(randomize_credentials)
proxyType(const CService &_proxy, bool _randomize_credentials = false)
: proxy(_proxy), randomize_credentials(_randomize_credentials)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/pubkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class CPubKey
}

//! Construct a public key from a byte vector.
CPubKey(const std::vector<unsigned char> &vch) { Set(vch.begin(), vch.end()); }
CPubKey(const std::vector<unsigned char> &_vch) { Set(_vch.begin(), _vch.end()); }
//! Simple read-only vector-like interface to the pubkey data.
unsigned int size() const { return GetLen(vch[0]); }
const unsigned char *begin() const { return vch; }
Expand Down
29 changes: 9 additions & 20 deletions src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,15 +607,10 @@ UniValue mkblocktemplate(const UniValue &params, CBlock *pblockOut)
vbavailable.push_back(Pair(gbt_vb_name(pos), consensusParams.vDeployments[pos].bit));
if (setClientRules.find(vbinfo.name) == setClientRules.end())
{
const struct ForkDeploymentInfo &vbinfo = VersionBitsDeploymentInfo[pos];
vbavailable.push_back(Pair(gbt_vb_name(pos), consensusParams.vDeployments[pos].bit));
if (setClientRules.find(vbinfo.name) == setClientRules.end())
if (!vbinfo.gbt_force)
{
if (!vbinfo.gbt_force)
{
// If the client doesn't support this, don't indicate it in the [default] version
pblock->nVersion &= ~VersionBitsMask(consensusParams, pos);
}
// If the client doesn't support this, don't indicate it in the [default] version
pblock->nVersion &= ~VersionBitsMask(consensusParams, pos);
}
}
break;
Expand All @@ -627,19 +622,13 @@ UniValue mkblocktemplate(const UniValue &params, CBlock *pblockOut)
aRules.push_back(gbt_vb_name(pos));
if (setClientRules.find(vbinfo.name) == setClientRules.end())
{
// Add to rules only
const struct ForkDeploymentInfo &vbinfo = VersionBitsDeploymentInfo[pos];
aRules.push_back(gbt_vb_name(pos));
if (setClientRules.find(vbinfo.name) == setClientRules.end())
// Not supported by the client; make sure it's safe to proceed
if (!vbinfo.gbt_force)
{
// Not supported by the client; make sure it's safe to proceed
if (!vbinfo.gbt_force)
{
// If we do anything other than throw an exception here, be sure version/force isn't sent to old
// clients
throw JSONRPCError(RPC_INVALID_PARAMETER,
strprintf("Support for '%s' rule requires explicit client support", vbinfo.name));
}
// If we do anything other than throw an exception here, be sure version/force isn't sent to old
// clients
throw JSONRPCError(RPC_INVALID_PARAMETER,
strprintf("Support for '%s' rule requires explicit client support", vbinfo.name));
}
}
break;
Expand Down
4 changes: 2 additions & 2 deletions src/script/interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ class MutableTransactionSignatureChecker : public TransactionSignatureChecker
public:
MutableTransactionSignatureChecker(const CMutableTransaction *txToIn,
unsigned int nInIn,
const CAmount &amount,
const CAmount &amountIn,
unsigned int flags = SCRIPT_ENABLE_SIGHASH_FORKID)
: TransactionSignatureChecker(&txTo, nInIn, amount, flags), txTo(*txToIn)
: TransactionSignatureChecker(&txTo, nInIn, amountIn, flags), txTo(*txToIn)
{
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/script/sigcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ class CachingTransactionSignatureChecker : public TransactionSignatureChecker
public:
CachingTransactionSignatureChecker(const CTransaction *txToIn,
unsigned int nInIn,
const CAmount &amount,
const CAmount &amountIn,
unsigned int flags,
bool storeIn = true)
: TransactionSignatureChecker(txToIn, nInIn, amount, flags), store(storeIn)
: TransactionSignatureChecker(txToIn, nInIn, amountIn, flags), store(storeIn)
{
}

Expand Down
16 changes: 8 additions & 8 deletions src/stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,28 +198,28 @@ class CStatHistory : public CStat<DataType, RecordType>
{
Clear(false);
}
CStatHistory(const char *name, unsigned int operation = STAT_OP_SUM)
: CStat<DataType, RecordType>(name), op(operation), timer(stat_io_service)
CStatHistory(const char *_name, unsigned int operation = STAT_OP_SUM)
: CStat<DataType, RecordType>(_name), op(operation), timer(stat_io_service)
{
Clear();
}

CStatHistory(const std::string &name, unsigned int operation = STAT_OP_SUM)
: CStat<DataType, RecordType>(name), op(operation), timer(stat_io_service)
CStatHistory(const std::string &_name, unsigned int operation = STAT_OP_SUM)
: CStat<DataType, RecordType>(_name), op(operation), timer(stat_io_service)
{
Clear();
}

void init(const char *name, unsigned int operation = STAT_OP_SUM)
void init(const char *_name, unsigned int operation = STAT_OP_SUM)
{
CStat<DataType, RecordType>::init(name);
CStat<DataType, RecordType>::init(_name);
op = operation;
Clear();
}

void init(const std::string &name, unsigned int operation = STAT_OP_SUM)
void init(const std::string &_name, unsigned int operation = STAT_OP_SUM)
{
CStat<DataType, RecordType>::init(name);
CStat<DataType, RecordType>::init(_name);
op = operation;
Clear();
}
Expand Down
2 changes: 1 addition & 1 deletion src/support/pagelocker.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ template <class Locker>
class LockedPageManagerBase
{
public:
LockedPageManagerBase(size_t page_size) : page_size(page_size)
LockedPageManagerBase(size_t _page_size) : page_size(_page_size)
{
// Determine bitmask for extracting page from address
assert(!(page_size & (page_size - 1))); // size must be power of two
Expand Down
8 changes: 4 additions & 4 deletions src/test/test_bitcoin_fuzzy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ class FuzzTest
class FuzzTestNet : public FuzzTest
{
public:
FuzzTestNet(const std::string &name) : FuzzTest(name), ds(nullptr) {}
bool init(const std::vector<char> &buffer)
FuzzTestNet(const std::string &_name) : FuzzTest(_name), ds(nullptr) {}
bool init(const std::vector<char> &_buffer)
{
FuzzTest::init(buffer);
FuzzTest::init(_buffer);
if (ds != nullptr)
delete ds;
ds = new CDataStream(buffer, SER_NETWORK, INIT_PROTO_VERSION);
ds = new CDataStream(_buffer, SER_NETWORK, INIT_PROTO_VERSION);
try
{
int nVersion;
Expand Down
6 changes: 3 additions & 3 deletions src/torcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class TorControlConnection
static void eventcb(struct bufferevent *bev, short what, void *ctx);
};

TorControlConnection::TorControlConnection(struct event_base *base) : base(base), b_conn(0) {}
TorControlConnection::TorControlConnection(struct event_base *_base) : base(_base), b_conn(0) {}
TorControlConnection::~TorControlConnection()
{
if (b_conn)
Expand Down Expand Up @@ -417,8 +417,8 @@ class TorController
static void reconnect_cb(evutil_socket_t fd, short what, void *arg);
};

TorController::TorController(struct event_base *baseIn, const std::string &target)
: base(baseIn), target(target), conn(base), reconnect(true), reconnect_ev(0),
TorController::TorController(struct event_base *baseIn, const std::string &_target)
: base(baseIn), target(_target), conn(base), reconnect(true), reconnect_ev(0),
reconnect_timeout(RECONNECT_TIMEOUT_START)
{
reconnect_ev = event_new(base, -1, 0, reconnect_cb, this);
Expand Down
24 changes: 12 additions & 12 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ bool CWallet::LoadWatchOnly(const CScript &dest) { return CCryptoKeyStore::AddWa
bool CWallet::Unlock(const SecureString &strWalletPassphrase)
{
CCrypter crypter;
CKeyingMaterial vMasterKey;
CKeyingMaterial _vMasterKey;

{
LOCK(cs_wallet);
Expand All @@ -310,9 +310,9 @@ bool CWallet::Unlock(const SecureString &strWalletPassphrase)
if (!crypter.SetKeyFromPassphrase(strWalletPassphrase, pMasterKey.second.vchSalt,
pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
return false;
if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, vMasterKey))
if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, _vMasterKey))
continue; // try another master key
if (CCryptoKeyStore::Unlock(vMasterKey))
if (CCryptoKeyStore::Unlock(_vMasterKey))
return true;
}
}
Expand All @@ -329,15 +329,15 @@ bool CWallet::ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase,
Lock();

CCrypter crypter;
CKeyingMaterial vMasterKey;
CKeyingMaterial _vMasterKey;
for (MasterKeyMap::value_type &pMasterKey : mapMasterKeys)
{
if (!crypter.SetKeyFromPassphrase(strOldWalletPassphrase, pMasterKey.second.vchSalt,
pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
return false;
if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, vMasterKey))
if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, _vMasterKey))
return false;
if (CCryptoKeyStore::Unlock(vMasterKey))
if (CCryptoKeyStore::Unlock(_vMasterKey))
{
int64_t nStartTime = GetTimeMillis();
crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt,
Expand All @@ -361,7 +361,7 @@ bool CWallet::ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase,
if (!crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt,
pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
return false;
if (!crypter.Encrypt(vMasterKey, pMasterKey.second.vchCryptedKey))
if (!crypter.Encrypt(_vMasterKey, pMasterKey.second.vchCryptedKey))
return false;
CWalletDB(strWalletFile).WriteMasterKey(pMasterKey.first, pMasterKey.second);
if (fWasLocked)
Expand Down Expand Up @@ -594,11 +594,11 @@ bool CWallet::EncryptWallet(const SecureString &strWalletPassphrase)
if (IsCrypted())
return false;

CKeyingMaterial vMasterKey;
CKeyingMaterial _vMasterKey;
RandAddSeedPerfmon();

vMasterKey.resize(WALLET_CRYPTO_KEY_SIZE);
GetRandBytes(&vMasterKey[0], WALLET_CRYPTO_KEY_SIZE);
_vMasterKey.resize(WALLET_CRYPTO_KEY_SIZE);
GetRandBytes(&_vMasterKey[0], WALLET_CRYPTO_KEY_SIZE);

CMasterKey kMasterKey;
RandAddSeedPerfmon();
Expand Down Expand Up @@ -626,7 +626,7 @@ bool CWallet::EncryptWallet(const SecureString &strWalletPassphrase)
if (!crypter.SetKeyFromPassphrase(
strWalletPassphrase, kMasterKey.vchSalt, kMasterKey.nDeriveIterations, kMasterKey.nDerivationMethod))
return false;
if (!crypter.Encrypt(vMasterKey, kMasterKey.vchCryptedKey))
if (!crypter.Encrypt(_vMasterKey, kMasterKey.vchCryptedKey))
return false;

{
Expand All @@ -645,7 +645,7 @@ bool CWallet::EncryptWallet(const SecureString &strWalletPassphrase)
pwalletdbEncryption->WriteMasterKey(nMasterKeyMaxID, kMasterKey);
}

if (!EncryptKeys(vMasterKey))
if (!EncryptKeys(_vMasterKey))
{
if (fFileBacked)
{
Expand Down
Loading

0 comments on commit a5c18a0

Please sign in to comment.