aboutsummaryrefslogtreecommitdiff
path: root/src/txdb.cpp
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/txdb.cpp
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/txdb.cpp')
-rw-r--r--src/txdb.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/txdb.cpp b/src/txdb.cpp
index 7a1d920117..91d6c98430 100644
--- a/src/txdb.cpp
+++ b/src/txdb.cpp
@@ -324,7 +324,7 @@ public:
void Unserialize(Stream &s) {
unsigned int nCode = 0;
// version
- int nVersionDummy;
+ unsigned int nVersionDummy;
::Unserialize(s, VARINT(nVersionDummy));
// header code
::Unserialize(s, VARINT(nCode));
@@ -351,7 +351,7 @@ public:
::Unserialize(s, CTxOutCompressor(vout[i]));
}
// coinbase height
- ::Unserialize(s, VARINT(nHeight));
+ ::Unserialize(s, VARINT(nHeight, VarIntMode::NONNEGATIVE_SIGNED));
}
};