Skip to content

Commit fe862c5

Browse files
Avoid division by zero in the case of a corrupt estimates file
1 parent 424be03 commit fe862c5

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/policy/fees.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ TxConfirmStats::TxConfirmStats(const std::vector<double>& defaultBuckets,
180180
: buckets(defaultBuckets), bucketMap(defaultBucketMap)
181181
{
182182
decay = _decay;
183+
assert(_scale != 0 && "_scale must be non-zero");
183184
scale = _scale;
184185
confAvg.resize(maxPeriods);
185186
for (unsigned int i = 0; i < maxPeriods; i++) {
@@ -418,6 +419,9 @@ void TxConfirmStats::Read(CAutoFile& filein, int nFileVersion, size_t numBuckets
418419
throw std::runtime_error("Corrupt estimates file. Decay must be between 0 and 1 (non-inclusive)");
419420
}
420421
filein >> scale;
422+
if (scale == 0) {
423+
throw std::runtime_error("Corrupt estimates file. Scale must be non-zero");
424+
}
421425
}
422426

423427
filein >> avg;

0 commit comments

Comments
 (0)