refactor: Avoid integer overflow in ApplyStats when activating snapshot

This commit is contained in:
MarcoFalke
2021-11-01 17:03:09 +01:00
parent fac01888d1
commit fa996c58e8
4 changed files with 9 additions and 4 deletions

View File

@@ -11,6 +11,7 @@
#include <index/coinstatsindex.h>
#include <serialize.h>
#include <uint256.h>
#include <util/overflow.h>
#include <util/system.h>
#include <validation.h>
@@ -82,7 +83,9 @@ static void ApplyStats(CCoinsStats& stats, const uint256& hash, const std::map<u
stats.nTransactions++;
for (auto it = outputs.begin(); it != outputs.end(); ++it) {
stats.nTransactionOutputs++;
stats.nTotalAmount += it->second.out.nValue;
if (stats.total_amount.has_value()) {
stats.total_amount = CheckedAdd(*stats.total_amount, it->second.out.nValue);
}
stats.nBogoSize += GetBogoSize(it->second.out.scriptPubKey);
}
}