Attention is currently required from: Krystian Hebel.

Krystian Hebel uploaded patch set #2 to this change.

View 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
Signed-off-by: Krystian Hebel <krystian.hebel@3mdeb.com>
---
M src/commonlib/bsd/include/commonlib/bsd/helpers.h
1 file changed, 33 insertions(+), 6 deletions(-)

git pull ssh://review.coreboot.org:29418/coreboot refs/changes/06/70106/2

To view, visit change 70106. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: Ie60a6ee82db80328e44639175272cc8097f36c3b
Gerrit-Change-Number: 70106
Gerrit-PatchSet: 2
Gerrit-Owner: Krystian Hebel <krystian.hebel@3mdeb.com>
Gerrit-Reviewer: Michał Żygowski <michal.zygowski@3mdeb.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-CC: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
Gerrit-Attention: Krystian Hebel <krystian.hebel@3mdeb.com>
Gerrit-MessageType: newpatchset