HomePhabricator

Add static_assert to prevent VARINT(<signed value>)

Description

Add static_assert to prevent VARINT(<signed value>)

Summary:
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 is a backport of Core PR9753

Test Plan:

make check
./test/functional/test_runner.py --extended

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D4187

Details