Limit variable scope

This commit is contained in:
practicalswift 2017-06-04 22:45:22 +02:00
parent f259263a7b
commit 90593ed92c
11 changed files with 21 additions and 23 deletions

View File

@ -112,7 +112,6 @@ static int CBCEncrypt(const T& enc, const unsigned char iv[AES_BLOCKSIZE], const
template <typename T> template <typename T>
static int CBCDecrypt(const T& dec, const unsigned char iv[AES_BLOCKSIZE], const unsigned char* data, int size, bool pad, unsigned char* out) static int CBCDecrypt(const T& dec, const unsigned char iv[AES_BLOCKSIZE], const unsigned char* data, int size, bool pad, unsigned char* out)
{ {
unsigned char padsize = 0;
int written = 0; int written = 0;
bool fail = false; bool fail = false;
const unsigned char* prev = iv; const unsigned char* prev = iv;
@ -136,7 +135,7 @@ static int CBCDecrypt(const T& dec, const unsigned char iv[AES_BLOCKSIZE], const
if (pad) { if (pad) {
// If used, padding size is the value of the last decrypted byte. For // If used, padding size is the value of the last decrypted byte. For
// it to be valid, It must be between 1 and AES_BLOCKSIZE. // it to be valid, It must be between 1 and AES_BLOCKSIZE.
padsize = *--out; unsigned char padsize = *--out;
fail = !padsize | (padsize > AES_BLOCKSIZE); fail = !padsize | (padsize > AES_BLOCKSIZE);
// If not well-formed, treat it as though there's no padding. // If not well-formed, treat it as though there's no padding.

View File

@ -855,13 +855,13 @@ bool CBlockPolicyEstimator::Read(CAutoFile& filein)
try { try {
LOCK(cs_feeEstimator); LOCK(cs_feeEstimator);
int nVersionRequired, nVersionThatWrote; int nVersionRequired, nVersionThatWrote;
unsigned int nFileBestSeenHeight, nFileHistoricalFirst, nFileHistoricalBest;
filein >> nVersionRequired >> nVersionThatWrote; filein >> nVersionRequired >> nVersionThatWrote;
if (nVersionRequired > CLIENT_VERSION) if (nVersionRequired > CLIENT_VERSION)
return error("CBlockPolicyEstimator::Read(): up-version (%d) fee estimate file", nVersionRequired); return error("CBlockPolicyEstimator::Read(): up-version (%d) fee estimate file", nVersionRequired);
// Read fee estimates file into temporary variables so existing data // Read fee estimates file into temporary variables so existing data
// structures aren't corrupted if there is an exception. // structures aren't corrupted if there is an exception.
unsigned int nFileBestSeenHeight;
filein >> nFileBestSeenHeight; filein >> nFileBestSeenHeight;
if (nVersionThatWrote < 149900) { if (nVersionThatWrote < 149900) {
@ -890,6 +890,7 @@ bool CBlockPolicyEstimator::Read(CAutoFile& filein)
} }
} }
else { // nVersionThatWrote >= 149900 else { // nVersionThatWrote >= 149900
unsigned int nFileHistoricalFirst, nFileHistoricalBest;
filein >> nFileHistoricalFirst >> nFileHistoricalBest; filein >> nFileHistoricalFirst >> nFileHistoricalBest;
if (nFileHistoricalFirst > nFileHistoricalBest || nFileHistoricalBest > nFileBestSeenHeight) { if (nFileHistoricalFirst > nFileHistoricalBest || nFileHistoricalBest > nFileBestSeenHeight) {
throw std::runtime_error("Corrupt estimates file. Historical block range for estimates is invalid"); throw std::runtime_error("Corrupt estimates file. Historical block range for estimates is invalid");

View File

@ -16,9 +16,10 @@ void CoinControlTreeWidget::keyPressEvent(QKeyEvent *event)
if (event->key() == Qt::Key_Space) // press spacebar -> select checkbox if (event->key() == Qt::Key_Space) // press spacebar -> select checkbox
{ {
event->ignore(); event->ignore();
int COLUMN_CHECKBOX = 0; if (this->currentItem()) {
if(this->currentItem()) int COLUMN_CHECKBOX = 0;
this->currentItem()->setCheckState(COLUMN_CHECKBOX, ((this->currentItem()->checkState(COLUMN_CHECKBOX) == Qt::Checked) ? Qt::Unchecked : Qt::Checked)); this->currentItem()->setCheckState(COLUMN_CHECKBOX, ((this->currentItem()->checkState(COLUMN_CHECKBOX) == Qt::Checked) ? Qt::Unchecked : Qt::Checked));
}
} }
else if (event->key() == Qt::Key_Escape) // press esc -> close dialog else if (event->key() == Qt::Key_Escape) // press esc -> close dialog
{ {

View File

@ -55,10 +55,9 @@ QVariant RecentRequestsTableModel::data(const QModelIndex &index, int role) cons
if(!index.isValid() || index.row() >= list.length()) if(!index.isValid() || index.row() >= list.length())
return QVariant(); return QVariant();
const RecentRequestEntry *rec = &list[index.row()];
if(role == Qt::DisplayRole || role == Qt::EditRole) if(role == Qt::DisplayRole || role == Qt::EditRole)
{ {
const RecentRequestEntry *rec = &list[index.row()];
switch(index.column()) switch(index.column())
{ {
case Date: case Date:

View File

@ -47,13 +47,14 @@ int TrafficGraphWidget::getGraphRangeMins() const
void TrafficGraphWidget::paintPath(QPainterPath &path, QQueue<float> &samples) void TrafficGraphWidget::paintPath(QPainterPath &path, QQueue<float> &samples)
{ {
int h = height() - YMARGIN * 2, w = width() - XMARGIN * 2; int sampleCount = samples.size();
int sampleCount = samples.size(), x = XMARGIN + w, y;
if(sampleCount > 0) { if(sampleCount > 0) {
int h = height() - YMARGIN * 2, w = width() - XMARGIN * 2;
int x = XMARGIN + w;
path.moveTo(x, YMARGIN + h); path.moveTo(x, YMARGIN + h);
for(int i = 0; i < sampleCount; ++i) { for(int i = 0; i < sampleCount; ++i) {
x = XMARGIN + w - w * i / DESIRED_SAMPLES; x = XMARGIN + w - w * i / DESIRED_SAMPLES;
y = YMARGIN + h - (int)(h * samples.at(i) / fMax); int y = YMARGIN + h - (int)(h * samples.at(i) / fMax);
path.lineTo(x, y); path.lineTo(x, y);
} }
path.lineTo(x, YMARGIN + h); path.lineTo(x, YMARGIN + h);

View File

@ -98,15 +98,13 @@ UniValue getnetworkhashps(const JSONRPCRequest& request)
UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGenerate, uint64_t nMaxTries, bool keepScript) UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGenerate, uint64_t nMaxTries, bool keepScript)
{ {
static const int nInnerLoopCount = 0x10000; static const int nInnerLoopCount = 0x10000;
int nHeightStart = 0;
int nHeightEnd = 0; int nHeightEnd = 0;
int nHeight = 0; int nHeight = 0;
{ // Don't keep cs_main locked { // Don't keep cs_main locked
LOCK(cs_main); LOCK(cs_main);
nHeightStart = chainActive.Height(); nHeight = chainActive.Height();
nHeight = nHeightStart; nHeightEnd = nHeight+nGenerate;
nHeightEnd = nHeightStart+nGenerate;
} }
unsigned int nExtraNonce = 0; unsigned int nExtraNonce = 0;
UniValue blockHashes(UniValue::VARR); UniValue blockHashes(UniValue::VARR);

View File

@ -838,7 +838,6 @@ UniValue sendrawtransaction(const JSONRPCRequest& request)
CTransactionRef tx(MakeTransactionRef(std::move(mtx))); CTransactionRef tx(MakeTransactionRef(std::move(mtx)));
const uint256& hashTx = tx->GetHash(); const uint256& hashTx = tx->GetHash();
bool fLimitFree = true;
CAmount nMaxRawTxFee = maxTxFee; CAmount nMaxRawTxFee = maxTxFee;
if (request.params.size() > 1 && request.params[1].get_bool()) if (request.params.size() > 1 && request.params[1].get_bool())
nMaxRawTxFee = 0; nMaxRawTxFee = 0;
@ -851,6 +850,7 @@ UniValue sendrawtransaction(const JSONRPCRequest& request)
// push to local node and sync with wallets // push to local node and sync with wallets
CValidationState state; CValidationState state;
bool fMissingInputs; bool fMissingInputs;
bool fLimitFree = true;
if (!AcceptToMemoryPool(mempool, state, std::move(tx), fLimitFree, &fMissingInputs, NULL, false, nMaxRawTxFee)) { if (!AcceptToMemoryPool(mempool, state, std::move(tx), fLimitFree, &fMissingInputs, NULL, false, nMaxRawTxFee)) {
if (state.IsInvalid()) { if (state.IsInvalid()) {
throw JSONRPCError(RPC_TRANSACTION_REJECTED, strprintf("%i: %s", state.GetRejectCode(), state.GetRejectReason())); throw JSONRPCError(RPC_TRANSACTION_REJECTED, strprintf("%i: %s", state.GetRejectCode(), state.GetRejectReason()));

View File

@ -141,10 +141,9 @@ static CScript PushAll(const std::vector<valtype>& values)
bool ProduceSignature(const BaseSignatureCreator& creator, const CScript& fromPubKey, SignatureData& sigdata) bool ProduceSignature(const BaseSignatureCreator& creator, const CScript& fromPubKey, SignatureData& sigdata)
{ {
CScript script = fromPubKey; CScript script = fromPubKey;
bool solved = true;
std::vector<valtype> result; std::vector<valtype> result;
txnouttype whichType; txnouttype whichType;
solved = SignStep(creator, script, result, whichType, SIGVERSION_BASE); bool solved = SignStep(creator, script, result, whichType, SIGVERSION_BASE);
bool P2SH = false; bool P2SH = false;
CScript subscript; CScript subscript;
sigdata.scriptWitness.stack.clear(); sigdata.scriptWitness.stack.clear();

View File

@ -402,12 +402,12 @@ BOOST_AUTO_TEST_CASE(test_CheckQueueControl_Locks)
{ {
boost::thread_group tg; boost::thread_group tg;
std::mutex m; std::mutex m;
bool has_lock {false};
bool has_tried {false};
bool done {false};
bool done_ack {false};
std::condition_variable cv; std::condition_variable cv;
{ {
bool has_lock {false};
bool has_tried {false};
bool done {false};
bool done_ack {false};
std::unique_lock<std::mutex> l(m); std::unique_lock<std::mutex> l(m);
tg.create_thread([&]{ tg.create_thread([&]{
CCheckQueueControl<FakeCheck> control(queue.get()); CCheckQueueControl<FakeCheck> control(queue.get());

View File

@ -361,7 +361,6 @@ void CDBEnv::CheckpointLSN(const std::string& strFile)
CDB::CDB(CWalletDBWrapper& dbw, const char* pszMode, bool fFlushOnCloseIn) : pdb(NULL), activeTxn(NULL) CDB::CDB(CWalletDBWrapper& dbw, const char* pszMode, bool fFlushOnCloseIn) : pdb(NULL), activeTxn(NULL)
{ {
int ret;
fReadOnly = (!strchr(pszMode, '+') && !strchr(pszMode, 'w')); fReadOnly = (!strchr(pszMode, '+') && !strchr(pszMode, 'w'));
fFlushOnClose = fFlushOnCloseIn; fFlushOnClose = fFlushOnCloseIn;
env = dbw.env; env = dbw.env;
@ -384,6 +383,7 @@ CDB::CDB(CWalletDBWrapper& dbw, const char* pszMode, bool fFlushOnCloseIn) : pdb
++env->mapFileUseCount[strFile]; ++env->mapFileUseCount[strFile];
pdb = env->mapDb[strFile]; pdb = env->mapDb[strFile];
if (pdb == NULL) { if (pdb == NULL) {
int ret;
pdb = new Db(env->dbenv, 0); pdb = new Db(env->dbenv, 0);
bool fMockDb = env->IsMock(); bool fMockDb = env->IsMock();

View File

@ -3196,10 +3196,10 @@ void CWallet::ReturnKey(int64_t nIndex)
bool CWallet::GetKeyFromPool(CPubKey& result, bool internal) bool CWallet::GetKeyFromPool(CPubKey& result, bool internal)
{ {
int64_t nIndex = 0;
CKeyPool keypool; CKeyPool keypool;
{ {
LOCK(cs_wallet); LOCK(cs_wallet);
int64_t nIndex = 0;
ReserveKeyFromKeyPool(nIndex, keypool, internal); ReserveKeyFromKeyPool(nIndex, keypool, internal);
if (nIndex == -1) if (nIndex == -1)
{ {