summaryrefslogtreecommitdiffstats
path: root/gl/xalloc-oversized.h
diff options
context:
space:
mode:
Diffstat (limited to 'gl/xalloc-oversized.h')
-rw-r--r--gl/xalloc-oversized.h13
1 files changed, 6 insertions, 7 deletions
diff --git a/gl/xalloc-oversized.h b/gl/xalloc-oversized.h
index 5dbdfb5..7f30f83 100644
--- a/gl/xalloc-oversized.h
+++ b/gl/xalloc-oversized.h
@@ -1,6 +1,6 @@
1/* xalloc-oversized.h -- memory allocation size checking 1/* xalloc-oversized.h -- memory allocation size checking
2 2
3 Copyright (C) 1990-2000, 2003-2004, 2006-2023 Free Software Foundation, Inc. 3 Copyright (C) 1990-2000, 2003-2004, 2006-2024 Free Software Foundation, Inc.
4 4
5 This file is free software: you can redistribute it and/or modify 5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as 6 it under the terms of the GNU Lesser General Public License as
@@ -29,8 +29,7 @@
29 is SIZE_MAX - 1. */ 29 is SIZE_MAX - 1. */
30#define __xalloc_oversized(n, s) \ 30#define __xalloc_oversized(n, s) \
31 ((s) != 0 \ 31 ((s) != 0 \
32 && ((size_t) (PTRDIFF_MAX < SIZE_MAX ? PTRDIFF_MAX : SIZE_MAX - 1) / (s) \ 32 && (PTRDIFF_MAX < SIZE_MAX ? PTRDIFF_MAX : SIZE_MAX - 1) / (s) < (n))
33 < (n)))
34 33
35/* Return 1 if and only if an array of N objects, each of size S, 34/* Return 1 if and only if an array of N objects, each of size S,
36 cannot exist reliably because its total size in bytes would exceed 35 cannot exist reliably because its total size in bytes would exceed
@@ -48,13 +47,13 @@
48#if 7 <= __GNUC__ && !defined __clang__ && PTRDIFF_MAX < SIZE_MAX 47#if 7 <= __GNUC__ && !defined __clang__ && PTRDIFF_MAX < SIZE_MAX
49# define xalloc_oversized(n, s) \ 48# define xalloc_oversized(n, s) \
50 __builtin_mul_overflow_p (n, s, (ptrdiff_t) 1) 49 __builtin_mul_overflow_p (n, s, (ptrdiff_t) 1)
51#elif (5 <= __GNUC__ && !defined __ICC && !__STRICT_ANSI__ \ 50#elif 5 <= __GNUC__ && !defined __ICC && PTRDIFF_MAX < SIZE_MAX
52 && PTRDIFF_MAX < SIZE_MAX)
53# define xalloc_oversized(n, s) \ 51# define xalloc_oversized(n, s) \
54 (__builtin_constant_p (n) && __builtin_constant_p (s) \ 52 (__builtin_constant_p (n) && __builtin_constant_p (s) \
55 ? __xalloc_oversized (n, s) \ 53 ? __xalloc_oversized (n, s) \
56 : ({ ptrdiff_t __xalloc_count; \ 54 : __extension__ \
57 __builtin_mul_overflow (n, s, &__xalloc_count); })) 55 ({ ptrdiff_t __xalloc_count; \
56 __builtin_mul_overflow (n, s, &__xalloc_count); }))
58 57
59/* Other compilers use integer division; this may be slower but is 58/* Other compilers use integer division; this may be slower but is
60 more portable. */ 59 more portable. */