12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- #ifndef XALLOC_OVERSIZED_H_
- #define XALLOC_OVERSIZED_H_
- #include <stddef.h>
- #include <stdint.h>
- #define __xalloc_oversized(n, s) \
- ((size_t) (PTRDIFF_MAX < SIZE_MAX ? PTRDIFF_MAX : SIZE_MAX - 1) / (s) < (n))
- #if PTRDIFF_MAX < SIZE_MAX
- typedef ptrdiff_t __xalloc_count_type;
- #else
- typedef size_t __xalloc_count_type;
- #endif
- #if 7 <= __GNUC__
- # define xalloc_oversized(n, s) \
- __builtin_mul_overflow_p (n, s, (__xalloc_count_type) 1)
- #elif 5 <= __GNUC__ && !__STRICT_ANSI__
- # define xalloc_oversized(n, s) \
- (__builtin_constant_p (n) && __builtin_constant_p (s) \
- ? __xalloc_oversized (n, s) \
- : ({ __xalloc_count_type __xalloc_count; \
- __builtin_mul_overflow (n, s, &__xalloc_count); }))
- #else
- # define xalloc_oversized(n, s) __xalloc_oversized (n, s)
- #endif
- #endif
|