aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2017-10-12 13:39:56 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2017-10-12 13:40:16 +0200
commita865b38bf33202b66ee2e72912fe164aa2a504c7 (patch)
tree13920b9ff109eb67c22ee9dac3472d903ae0e549 /src
parent892809309c1bc370677241a715e57a2744f94323 (diff)
parent55509f1a11003837714071d05ea878b340757a76 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/policy/fees.cpp1
-rw-r--r--src/qt/coincontroldialog.cpp1
-rw-r--r--src/wallet/wallet.cpp1
3 files changed, 3 insertions, 0 deletions
diff --git a/src/policy/fees.cpp b/src/policy/fees.cpp
index 8056f385ab..dcf49de5f1 100644
--- a/src/policy/fees.cpp
+++ b/src/policy/fees.cpp
@@ -503,6 +503,7 @@ void TxConfirmStats::removeTx(unsigned int entryHeight, unsigned int nBestSeenHe
}
}
if (!inBlock && (unsigned int)blocksAgo >= scale) { // Only counts as a failure if not confirmed for entire period
+ assert(scale != 0);
unsigned int periodsAgo = blocksAgo / scale;
for (size_t i = 0; i < periodsAgo && i < failAvg.size(); i++) {
failAvg[i][bucketindex]++;
diff --git a/src/qt/coincontroldialog.cpp b/src/qt/coincontroldialog.cpp
index 3ca43eae22..6952eb5064 100644
--- a/src/qt/coincontroldialog.cpp
+++ b/src/qt/coincontroldialog.cpp
@@ -582,6 +582,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
QString toolTipDust = tr("This label turns red if any recipient receives an amount smaller than the current dust threshold.");
// how many satoshis the estimated fee can vary per byte we guess wrong
+ assert(nBytes != 0);
double dFeeVary = (double)nPayFee / nBytes;
QString toolTip4 = tr("Can vary +/- %1 satoshi(s) per input.").arg(dFeeVary);
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 925b474d73..50c1375f44 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -2704,6 +2704,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
if (recipient.fSubtractFeeFromAmount)
{
+ assert(nSubtractFeeFromAmount != 0);
txout.nValue -= nFeeRet / nSubtractFeeFromAmount; // Subtract fee equally from each selected recipient
if (fFirst) // first receiver pays the remainder not divisible by output count