diff options
Diffstat (limited to 'include/lib/utils_def.h')
-rw-r--r-- | include/lib/utils_def.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/include/lib/utils_def.h b/include/lib/utils_def.h index 8abc73c09..31b129454 100644 --- a/include/lib/utils_def.h +++ b/include/lib/utils_def.h @@ -68,6 +68,13 @@ (((ptr) > UINTPTR_MAX - (inc)) ? 1 : 0) /* + * Evaluates to 1 if (u32 + inc) overflows, 0 otherwise. + * Both arguments must be 32-bit unsigned integers (i.e. effectively uint32_t). + */ +#define check_u32_overflow(u32, inc) \ + ((u32) > (UINT32_MAX - (inc)) ? 1 : 0) + +/* * For those constants to be shared between C and other sources, apply a 'u' * or 'ull' suffix to the argument only in C, to avoid undefined or unintended * behaviour. |