Merge #12963: Fix Clang Static Analyzer warnings

159c32d1f1 Add assertion to guide static analyzers. Clang Static Analyzer needs this guidance. (practicalswift)
fd447a6efe Fix dead stores. Values were stored but never read. Limit scope. (practicalswift)

Pull request description:

  Fix Clang Static Analyzer warnings reported by @kallewoof in #12961:

  * Fix dead stores. Values were stored but never read.
  * Add assertion to guide static analyzers. See #12961 for details.

Tree-SHA512: 83dbec821f45217637316bee978e7543f2d2caeb7f7b0b3aec107fede0fff8baa756da8f6b761ae0d38537740839ac9752f6689109c38a4b05c0c041aaa3a1fb
This commit is contained in:
MarcoFalke 2018-05-14 10:45:04 -04:00
commit c5870ab689
No known key found for this signature in database
GPG Key ID: D2EA4850E7528B25
3 changed files with 6 additions and 11 deletions

View File

@ -525,6 +525,7 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
// Need to update only after we know CreateNewBlock succeeded
pindexPrev = pindexPrevNew;
}
assert(pindexPrev);
CBlock* pblock = &pblocktemplate->block; // pointer for convenience
const Consensus::Params& consensusParams = Params().GetConsensus();

View File

@ -1065,6 +1065,7 @@ static void TestOtherProcess(fs::path dirname, std::string lockname, int fd)
ReleaseDirectoryLocks();
ch = true; // Always succeeds
rv = write(fd, &ch, 1);
assert(rv == 1);
break;
case ExitCommand:
close(fd);

View File

@ -536,19 +536,9 @@ BOOST_AUTO_TEST_CASE(SelectCoins_test)
std::exponential_distribution<double> distribution (100);
FastRandomContext rand;
// Output stuff
CAmount out_value = 0;
CoinSet out_set;
CAmount target = 0;
bool bnb_used;
// Run this test 100 times
for (int i = 0; i < 100; ++i)
{
// Reset
out_value = 0;
target = 0;
out_set.clear();
empty_wallet();
// Make a wallet with 1000 exponentially distributed random inputs
@ -561,11 +551,14 @@ BOOST_AUTO_TEST_CASE(SelectCoins_test)
CFeeRate rate(rand.randrange(300) + 100);
// Generate a random target value between 1000 and wallet balance
target = rand.randrange(balance - 1000) + 1000;
CAmount target = rand.randrange(balance - 1000) + 1000;
// Perform selection
CoinSelectionParams coin_selection_params_knapsack(false, 34, 148, CFeeRate(0), 0);
CoinSelectionParams coin_selection_params_bnb(true, 34, 148, CFeeRate(0), 0);
CoinSet out_set;
CAmount out_value = 0;
bool bnb_used = false;
BOOST_CHECK(testWallet.SelectCoinsMinConf(target, filter_standard, vCoins, out_set, out_value, coin_selection_params_bnb, bnb_used) ||
testWallet.SelectCoinsMinConf(target, filter_standard, vCoins, out_set, out_value, coin_selection_params_knapsack, bnb_used));
BOOST_CHECK_GE(out_value, target);