From 8c2dc5ccec7c6726b5414a2b62a596f0531d0463 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 16 Nov 2015 23:01:22 +0100 Subject: add macros for overflow check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- include/slibc/internals.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'include') diff --git a/include/slibc/internals.h b/include/slibc/internals.h index 099e2e7..b3f6235 100644 --- a/include/slibc/internals.h +++ b/include/slibc/internals.h @@ -18,9 +18,24 @@ #ifndef _SLIBC_INTERNALS_H #define _SLIBC_INTERNALS_H +#include + + #define _(msg) msg +#define OVERFLOW(op, a, b, res, errnum, failrc) \ + do \ + if (__builtin_##op##_overflow(a, b, res)) \ + return errno = (errnum), (failrc); \ + while (0) + + +#define MEM_OVERFLOW(op, a, b, res) \ + OVERFLOW(op, a, b, res, ENOMEM, NULL) + + + #endif -- cgit v1.2.3-70-g09d2