mirror of
https://git.savannah.gnu.org/git/grub.git
synced 2026-10-24 16:19:22 +00:00
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>
This commit is contained in:
1 parent
a4d3fbdff1
commit
68708c4503
3 files changed
+47
-20
No files matched your search
@@ -48,4 +48,12 @@
|
||||
# define WARN_UNUSED_RESULT
|
||||
#endif
|
||||
|
||||
#if defined(__clang__) && defined(__clang_major__) && defined(__clang_minor__)
|
||||
# define CLANG_PREREQ(maj,min) \
|
||||
((__clang_major__ > (maj)) || \
|
||||
(__clang_major__ == (maj) && __clang_minor__ >= (min)))
|
||||
#else
|
||||
# define CLANG_PREREQ(maj,min) 0
|
||||
#endif
|
||||
|
||||
#endif /* ! GRUB_COMPILER_HEADER */
|
||||
Reference in new issue
Block a user