pick better umul_overflow variant based on size_t size

This commit is contained in:
daan 2019-10-17 09:52:10 -07:00
parent 4609537b8a
commit f3a162f095

View File

@ -156,10 +156,10 @@ bool _mi_page_is_valid(mi_page_t* page);
#define MI_MUL_NO_OVERFLOW ((size_t)1 << (4*sizeof(size_t))) // sqrt(SIZE_MAX)
static inline bool mi_mul_overflow(size_t count, size_t size, size_t* total) {
#if __has_builtin(__builtin_umul_overflow) || __GNUC__ >= 5
#include <limits.h> // INT_MAX, LONG_MAX
#if (INTPTR_MAX == INT_MAX)
#include <limits.h> // UINT_MAX, ULONG_MAX
#if (SIZE_MAX == UINT_MAX)
return __builtin_umul_overflow(count, size, total);
#elif (INTPTR_MAX == LONG_MAX)
#elif (SIZE_MAX == ULONG_MAX)
return __builtin_umull_overflow(count, size, total);
#else
return __builtin_umulll_overflow(count, size, total);