mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-07-28 09:42:48 +02:00
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.
This commit is contained in:
@@ -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));
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user