]> git.ipfire.org Git - thirdparty/grub.git/commit
safemath: Add some arithmetic primitives that check for overflow
authorPeter Jones <pjones@redhat.com>
Mon, 15 Jun 2020 14:58:42 +0000 (10:58 -0400)
committerDaniel Kiper <daniel.kiper@oracle.com>
Wed, 29 Jul 2020 14:55:47 +0000 (16:55 +0200)
commit68708c4503018d61dbcce7ac11cbb511d6425f4d
tree81f2d56bcf5c8e29b993951511a1a39b27898d52
parenta4d3fbdff1e3ca8f87642af2ac8752c30c617a3e
safemath: Add some arithmetic primitives that check for overflow

This adds a new header, include/grub/safemath.h, that includes easy to
use wrappers for __builtin_{add,sub,mul}_overflow() declared like:

  bool OP(a, b, res)

where OP is grub_add, grub_sub or grub_mul. OP() returns true in the
case where the operation would overflow and res is not modified.
Otherwise, false is returned and the operation is executed.

These arithmetic primitives require newer compiler versions. So, bump
these requirements in the INSTALL file too.

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
INSTALL
include/grub/compiler.h
include/grub/safemath.h [new file with mode: 0644]