From 55509f1a11003837714071d05ea878b340757a76 Mon Sep 17 00:00:00 2001 From: practicalswift Date: Mon, 28 Aug 2017 09:20:50 +0200 Subject: [PATCH] Document assumptions that are being made to avoid division by zero --- src/policy/fees.cpp | 1 + src/qt/coincontroldialog.cpp | 1 + src/wallet/wallet.cpp | 1 + 3 files changed, 3 insertions(+) diff --git a/src/policy/fees.cpp b/src/policy/fees.cpp index b9476407cf163..5c92a0eb41a7d 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 f3ee0fbe393ae..0225dd3cd6fef 100644 --- a/src/qt/coincontroldialog.cpp +++ b/src/qt/coincontroldialog.cpp @@ -581,6 +581,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 291bcc7a2075a..6d94154da84b5 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2741,6 +2741,7 @@ bool CWallet::CreateTransaction(const std::vector& 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