Page MenuHomePhabricator

univalue: Avoid brittle, narrowing and verbose integral type confusions
ClosedPublic

Authored by Fabien on Jun 5 2024, 10:05.

Details

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

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable