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

Provenance
Russell Yanofsky <russ@yanofsky.org>Authored on Feb 13 2017, 18:41
deadalnixCommitted on Oct 1 2019, 15:03
deadalnixPushed on Oct 1 2019, 15:03
Reviewer
Restricted Project
Differential Revision
D4187: Add static_assert to prevent VARINT(<signed value>)
Parents
rABC7961960585b5: [CMAKE] Enable Large File Support on platforms that don't enable it by default
Branches
Unknown
Tags
Unknown