Skip to content

Commit 76f268b

Browse files
committed
Merge #10521: Limit variable scope
90593ed Limit variable scope (practicalswift) Tree-SHA512: 4719e303688a31aefbe1d239e86b21dd3c2045524e08bd628c6ba0c6c2a97de14d04305b9beafe0b1dcde7229793e6663168953f192e88ed409be5c30fd2a9a9
2 parents 29f80cd + 90593ed commit 76f268b

File tree

11 files changed

+21
-23
lines changed

11 files changed

+21
-23
lines changed

src/crypto/aes.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ static int CBCEncrypt(const T& enc, const unsigned char iv[AES_BLOCKSIZE], const
112112
template <typename T>
113113
static int CBCDecrypt(const T& dec, const unsigned char iv[AES_BLOCKSIZE], const unsigned char* data, int size, bool pad, unsigned char* out)
114114
{
115-
unsigned char padsize = 0;
116115
int written = 0;
117116
bool fail = false;
118117
const unsigned char* prev = iv;
@@ -136,7 +135,7 @@ static int CBCDecrypt(const T& dec, const unsigned char iv[AES_BLOCKSIZE], const
136135
if (pad) {
137136
// If used, padding size is the value of the last decrypted byte. For
138137
// it to be valid, It must be between 1 and AES_BLOCKSIZE.
139-
padsize = *--out;
138+
unsigned char padsize = *--out;
140139
fail = !padsize | (padsize > AES_BLOCKSIZE);
141140

142141
// If not well-formed, treat it as though there's no padding.

src/policy/fees.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,13 +855,13 @@ bool CBlockPolicyEstimator::Read(CAutoFile& filein)
855855
try {
856856
LOCK(cs_feeEstimator);
857857
int nVersionRequired, nVersionThatWrote;
858-
unsigned int nFileBestSeenHeight, nFileHistoricalFirst, nFileHistoricalBest;
859858
filein >> nVersionRequired >> nVersionThatWrote;
860859
if (nVersionRequired > CLIENT_VERSION)
861860
return error("CBlockPolicyEstimator::Read(): up-version (%d) fee estimate file", nVersionRequired);
862861

863862
// Read fee estimates file into temporary variables so existing data
864863
// structures aren't corrupted if there is an exception.
864+
unsigned int nFileBestSeenHeight;
865865
filein >> nFileBestSeenHeight;
866866

867867
if (nVersionThatWrote < 149900) {
@@ -890,6 +890,7 @@ bool CBlockPolicyEstimator::Read(CAutoFile& filein)
890890
}
891891
}
892892
else { // nVersionThatWrote >= 149900
893+
unsigned int nFileHistoricalFirst, nFileHistoricalBest;
893894
filein >> nFileHistoricalFirst >> nFileHistoricalBest;
894895
if (nFileHistoricalFirst > nFileHistoricalBest || nFileHistoricalBest > nFileBestSeenHeight) {
895896
throw std::runtime_error("Corrupt estimates file. Historical block range for estimates is invalid");

src/qt/coincontroltreewidget.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ void CoinControlTreeWidget::keyPressEvent(QKeyEvent *event)
1616
if (event->key() == Qt::Key_Space) // press spacebar -> select checkbox
1717
{
1818
event->ignore();
19-
int COLUMN_CHECKBOX = 0;
20-
if(this->currentItem())
19+
if (this->currentItem()) {
20+
int COLUMN_CHECKBOX = 0;
2121
this->currentItem()->setCheckState(COLUMN_CHECKBOX, ((this->currentItem()->checkState(COLUMN_CHECKBOX) == Qt::Checked) ? Qt::Unchecked : Qt::Checked));
22+
}
2223
}
2324
else if (event->key() == Qt::Key_Escape) // press esc -> close dialog
2425
{

src/qt/recentrequeststablemodel.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,9 @@ QVariant RecentRequestsTableModel::data(const QModelIndex &index, int role) cons
5555
if(!index.isValid() || index.row() >= list.length())
5656
return QVariant();
5757

58-
const RecentRequestEntry *rec = &list[index.row()];
59-
6058
if(role == Qt::DisplayRole || role == Qt::EditRole)
6159
{
60+
const RecentRequestEntry *rec = &list[index.row()];
6261
switch(index.column())
6362
{
6463
case Date:

src/qt/trafficgraphwidget.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@ int TrafficGraphWidget::getGraphRangeMins() const
4747

4848
void TrafficGraphWidget::paintPath(QPainterPath &path, QQueue<float> &samples)
4949
{
50-
int h = height() - YMARGIN * 2, w = width() - XMARGIN * 2;
51-
int sampleCount = samples.size(), x = XMARGIN + w, y;
50+
int sampleCount = samples.size();
5251
if(sampleCount > 0) {
52+
int h = height() - YMARGIN * 2, w = width() - XMARGIN * 2;
53+
int x = XMARGIN + w;
5354
path.moveTo(x, YMARGIN + h);
5455
for(int i = 0; i < sampleCount; ++i) {
5556
x = XMARGIN + w - w * i / DESIRED_SAMPLES;
56-
y = YMARGIN + h - (int)(h * samples.at(i) / fMax);
57+
int y = YMARGIN + h - (int)(h * samples.at(i) / fMax);
5758
path.lineTo(x, y);
5859
}
5960
path.lineTo(x, YMARGIN + h);

src/rpc/mining.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,13 @@ UniValue getnetworkhashps(const JSONRPCRequest& request)
9696
UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGenerate, uint64_t nMaxTries, bool keepScript)
9797
{
9898
static const int nInnerLoopCount = 0x10000;
99-
int nHeightStart = 0;
10099
int nHeightEnd = 0;
101100
int nHeight = 0;
102101

103102
{ // Don't keep cs_main locked
104103
LOCK(cs_main);
105-
nHeightStart = chainActive.Height();
106-
nHeight = nHeightStart;
107-
nHeightEnd = nHeightStart+nGenerate;
104+
nHeight = chainActive.Height();
105+
nHeightEnd = nHeight+nGenerate;
108106
}
109107
unsigned int nExtraNonce = 0;
110108
UniValue blockHashes(UniValue::VARR);

src/rpc/rawtransaction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,6 @@ UniValue sendrawtransaction(const JSONRPCRequest& request)
852852
CTransactionRef tx(MakeTransactionRef(std::move(mtx)));
853853
const uint256& hashTx = tx->GetHash();
854854

855-
bool fLimitFree = true;
856855
CAmount nMaxRawTxFee = maxTxFee;
857856
if (request.params.size() > 1 && request.params[1].get_bool())
858857
nMaxRawTxFee = 0;
@@ -868,6 +867,7 @@ UniValue sendrawtransaction(const JSONRPCRequest& request)
868867
// push to local node and sync with wallets
869868
CValidationState state;
870869
bool fMissingInputs;
870+
bool fLimitFree = true;
871871
if (!AcceptToMemoryPool(mempool, state, std::move(tx), fLimitFree, &fMissingInputs, NULL, false, nMaxRawTxFee)) {
872872
if (state.IsInvalid()) {
873873
throw JSONRPCError(RPC_TRANSACTION_REJECTED, strprintf("%i: %s", state.GetRejectCode(), state.GetRejectReason()));

src/script/sign.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,9 @@ static CScript PushAll(const std::vector<valtype>& values)
141141
bool ProduceSignature(const BaseSignatureCreator& creator, const CScript& fromPubKey, SignatureData& sigdata)
142142
{
143143
CScript script = fromPubKey;
144-
bool solved = true;
145144
std::vector<valtype> result;
146145
txnouttype whichType;
147-
solved = SignStep(creator, script, result, whichType, SIGVERSION_BASE);
146+
bool solved = SignStep(creator, script, result, whichType, SIGVERSION_BASE);
148147
bool P2SH = false;
149148
CScript subscript;
150149
sigdata.scriptWitness.stack.clear();

src/test/checkqueue_tests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,12 @@ BOOST_AUTO_TEST_CASE(test_CheckQueueControl_Locks)
402402
{
403403
boost::thread_group tg;
404404
std::mutex m;
405-
bool has_lock {false};
406-
bool has_tried {false};
407-
bool done {false};
408-
bool done_ack {false};
409405
std::condition_variable cv;
410406
{
407+
bool has_lock {false};
408+
bool has_tried {false};
409+
bool done {false};
410+
bool done_ack {false};
411411
std::unique_lock<std::mutex> l(m);
412412
tg.create_thread([&]{
413413
CCheckQueueControl<FakeCheck> control(queue.get());

src/wallet/db.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,6 @@ void CDBEnv::CheckpointLSN(const std::string& strFile)
360360

361361
CDB::CDB(CWalletDBWrapper& dbw, const char* pszMode, bool fFlushOnCloseIn) : pdb(NULL), activeTxn(NULL)
362362
{
363-
int ret;
364363
fReadOnly = (!strchr(pszMode, '+') && !strchr(pszMode, 'w'));
365364
fFlushOnClose = fFlushOnCloseIn;
366365
env = dbw.env;
@@ -383,6 +382,7 @@ CDB::CDB(CWalletDBWrapper& dbw, const char* pszMode, bool fFlushOnCloseIn) : pdb
383382
++env->mapFileUseCount[strFile];
384383
pdb = env->mapDb[strFile];
385384
if (pdb == NULL) {
385+
int ret;
386386
pdb = new Db(env->dbenv, 0);
387387

388388
bool fMockDb = env->IsMock();

0 commit comments

Comments
 (0)