aboutsummaryrefslogtreecommitdiff
path: root/src/undo.h
diff options
context:
space:
mode:
authorRussell Yanofsky <russ@yanofsky.org>2017-02-13 13:41:02 -0500
committerRussell Yanofsky <russ@yanofsky.org>2018-03-15 18:57:55 -0500
commit499d95e278f34790660a2b9baf5525e0def1485a (patch)
treef95140f9f7ba7344345e96c5da618d48e5b5d44b /src/undo.h
parent7be9a9a570c1140048f8781ced1111e1d930e517 (diff)
Add static_assert to prevent VARINT(<signed value>)
Using VARINT with signed types is dangerous because negative values will appear to serialize correctly, but then deserialize as positive values mod 128. This commit changes the VARINT macro to trigger an error by default if called with an signed value, and updates broken uses of VARINT to pass a special flag that lets them keep working with no change in behavior.
Diffstat (limited to 'src/undo.h')
-rw-r--r--src/undo.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/undo.h b/src/undo.h
index 7aae034de2..6fc25b9853 100644
--- a/src/undo.h
+++ b/src/undo.h
@@ -25,7 +25,7 @@ class TxInUndoSerializer
public:
template<typename Stream>
void Serialize(Stream &s) const {
- ::Serialize(s, VARINT(txout->nHeight * 2 + (txout->fCoinBase ? 1 : 0)));
+ ::Serialize(s, VARINT(txout->nHeight * 2 + (txout->fCoinBase ? 1 : 0), VarIntMode::NONNEGATIVE_SIGNED));
if (txout->nHeight > 0) {
// Required to maintain compatibility with older undo format.
::Serialize(s, (unsigned char)0);
@@ -51,7 +51,7 @@ public:
// Old versions stored the version number for the last spend of
// a transaction's outputs. Non-final spends were indicated with
// height = 0.
- int nVersionDummy;
+ unsigned int nVersionDummy;
::Unserialize(s, VARINT(nVersionDummy));
}
::Unserialize(s, CTxOutCompressor(REF(txout->out)));