HomePhabricator

univalue: Avoid brittle, narrowing and verbose integral type confusions

Description

univalue: Avoid brittle, narrowing and verbose integral type confusions

Summary:

As UniValue provides several constructors for integral types, the
compiler is unable to select one if the passed type does not exactly
match. This is unintuitive for developers and forces them to write
verbose and brittle code. (Refer to -Wnarrowing compiler warning)

For example, there are many places where an unsigned int is cast to a
signed int. While the cast is safe in practice, it is still needlessly
verbose and confusing as the value can never be negative. In fact it
might even be unsafe if the unsigned value is large enough to map to a
negative signed one.

Fix this issue and other (minor) type issues.

Backport of core#25611.

Depends on D16280.

Test Plan:

ninja all check-all

Reviewers: #bitcoin_abc, PiRK

Reviewed By: #bitcoin_abc, PiRK

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

Details

Provenance
MacroFake <falke.marco@gmail.com>Authored on Jul 14 2022, 08:45
FabienCommitted on Jun 5 2024, 17:49
FabienPushed on Jun 5 2024, 17:49
Reviewer
Restricted Project
Differential Revision
D16281: univalue: Avoid brittle, narrowing and verbose integral type confusions
Parents
rABC28b96d189562: univalue: Throw exception on invalid pushes over silent ignore
Branches
Unknown
Tags
Unknown