mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
Check for overflow when calculating sum of outputs
This commit is contained in:
parent
67de1ee8bc
commit
f65c9ad40f
1 changed files with 5 additions and 2 deletions
|
@ -9,6 +9,8 @@
|
||||||
#include <tinyformat.h>
|
#include <tinyformat.h>
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
std::string COutPoint::ToString() const
|
std::string COutPoint::ToString() const
|
||||||
{
|
{
|
||||||
return strprintf("COutPoint(%s, %u)", hash.ToString().substr(0,10), n);
|
return strprintf("COutPoint(%s, %u)", hash.ToString().substr(0,10), n);
|
||||||
|
@ -84,10 +86,11 @@ CAmount CTransaction::GetValueOut() const
|
||||||
{
|
{
|
||||||
CAmount nValueOut = 0;
|
CAmount nValueOut = 0;
|
||||||
for (const auto& tx_out : vout) {
|
for (const auto& tx_out : vout) {
|
||||||
nValueOut += tx_out.nValue;
|
if (!MoneyRange(tx_out.nValue) || !MoneyRange(nValueOut + tx_out.nValue))
|
||||||
if (!MoneyRange(tx_out.nValue) || !MoneyRange(nValueOut))
|
|
||||||
throw std::runtime_error(std::string(__func__) + ": value out of range");
|
throw std::runtime_error(std::string(__func__) + ": value out of range");
|
||||||
|
nValueOut += tx_out.nValue;
|
||||||
}
|
}
|
||||||
|
assert(MoneyRange(nValueOut));
|
||||||
return nValueOut;
|
return nValueOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue