Skip to content

Commit a865b38

Browse files
committed
Merge #11133: Document assumptions that are being made to avoid division by zero
55509f1 Document assumptions that are being made to avoid division by zero (practicalswift) Pull request description: Document assumptions (via `assert(…)`:s) that are being made to avoid division by zero. Rationale: * Make it clear to human reviewers and non-human static analyzers that what might look like potential division by zero cases are written the way they are intentionally (these cases are currently flagged by various static analyzers). Tree-SHA512: bbb67b1370afd8f39bda35f9e3a20f4325f017d94cc1bfac3b0d36c9f34c2d95a9efe11efe44db29fb4aadd25d8276d8f0e03c8806ac64f0d21d821912e13b8e
2 parents 8928093 + 55509f1 commit a865b38

File tree

3 files changed

+3
-0
lines changed

3 files changed

+3
-0
lines changed

src/policy/fees.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ void TxConfirmStats::removeTx(unsigned int entryHeight, unsigned int nBestSeenHe
503503
}
504504
}
505505
if (!inBlock && (unsigned int)blocksAgo >= scale) { // Only counts as a failure if not confirmed for entire period
506+
assert(scale != 0);
506507
unsigned int periodsAgo = blocksAgo / scale;
507508
for (size_t i = 0; i < periodsAgo && i < failAvg.size(); i++) {
508509
failAvg[i][bucketindex]++;

src/qt/coincontroldialog.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
582582
QString toolTipDust = tr("This label turns red if any recipient receives an amount smaller than the current dust threshold.");
583583

584584
// how many satoshis the estimated fee can vary per byte we guess wrong
585+
assert(nBytes != 0);
585586
double dFeeVary = (double)nPayFee / nBytes;
586587

587588
QString toolTip4 = tr("Can vary +/- %1 satoshi(s) per input.").arg(dFeeVary);

src/wallet/wallet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,6 +2704,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
27042704

27052705
if (recipient.fSubtractFeeFromAmount)
27062706
{
2707+
assert(nSubtractFeeFromAmount != 0);
27072708
txout.nValue -= nFeeRet / nSubtractFeeFromAmount; // Subtract fee equally from each selected recipient
27082709

27092710
if (fFirst) // first receiver pays the remainder not divisible by output count

0 commit comments

Comments
 (0)