aboutsummaryrefslogtreecommitdiff
path: root/src/undo.h
diff options
context:
space:
mode:
authorpierrenn <git@pnn.sh>2020-03-26 07:48:48 +0900
committerpierrenn <git@pnn.sh>2020-03-28 08:38:07 +0900
commite980214bc4fd49530e8d50fe0a6657b8583bc6b5 (patch)
tree75d1988a8bc31563704fd8dba936a175624a0eae /src/undo.h
parent97b0687501cee77a9170f9e288755a5d268e9bd4 (diff)
downloadbitcoin-e980214bc4fd49530e8d50fe0a6657b8583bc6b5.tar.xz
serialization: prevent int overflow for big Coin::nHeight
Diffstat (limited to 'src/undo.h')
-rw-r--r--src/undo.h6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/undo.h b/src/undo.h
index 47f132c7d8..80bbd146f3 100644
--- a/src/undo.h
+++ b/src/undo.h
@@ -24,7 +24,7 @@ struct TxInUndoFormatter
{
template<typename Stream>
void Ser(Stream &s, const Coin& txout) {
- ::Serialize(s, VARINT(txout.nHeight * 2 + (txout.fCoinBase ? 1u : 0u)));
+ ::Serialize(s, VARINT(txout.nHeight * uint32_t{2} + txout.fCoinBase ));
if (txout.nHeight > 0) {
// Required to maintain compatibility with older undo format.
::Serialize(s, (unsigned char)0);
@@ -34,9 +34,9 @@ struct TxInUndoFormatter
template<typename Stream>
void Unser(Stream &s, Coin& txout) {
- unsigned int nCode = 0;
+ uint32_t nCode = 0;
::Unserialize(s, VARINT(nCode));
- txout.nHeight = nCode / 2;
+ txout.nHeight = nCode >> 1;
txout.fCoinBase = nCode & 1;
if (txout.nHeight > 0) {
// Old versions stored the version number for the last spend of