Attention is currently required from: Krystian Hebel.
Krystian Hebel uploaded patch set #3 to this change.
commonlib/helpers.h: use unsigned literals in definitions
This protects against some of unintentional integer promotions, e.g.:
uint16_t freq_mhz = 2148; // or bigger
uint64_t freq = freq_mhz * MHz;
In this example, MHz used to be treated as int32_t, and because int32_t
can represent every value that uin16_t can, multiplication was being
performed with both arguments treated as int32_t. During assignment,
result of multiplication is promoted to int64_t (because it can
represent each value that int32_t can), and finally implicitly
converted to uint64_t.
Promotions preserve the value, including the sign, so if result of
multiplication is negative, the same negative number (but extended to
64 bits) is converted to unsigned number.
Signed-off-by: Krystian Hebel <krystian.hebel@3mdeb.com>
Change-Id: Ie60a6ee82db80328e44639175272cc8097f36c3b
---
M src/commonlib/bsd/include/commonlib/bsd/helpers.h
1 file changed, 32 insertions(+), 6 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/06/70106/3
To view, visit change 70106. To unsubscribe, or for help writing mail filters, visit settings.