summaryrefslogtreecommitdiffstats
path: root/gl/m4/realloc.m4
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-12-28 12:13:40 +0100
committerLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-12-28 12:13:40 +0100
commitb0afb8fe0ff1d87165af9df61501197a06240dda (patch)
tree274ac6a96c53ef4c19ab4974ce24a06a233128c5 /gl/m4/realloc.m4
parent68fc05381ee5fa0aee1413118fbb3d81ca888b09 (diff)
downloadmonitoring-plugins-b0afb8fe0ff1d87165af9df61501197a06240dda.tar.gz
Sync with Gnulib stable-202507 code (a8ac9f9ce5)
Diffstat (limited to 'gl/m4/realloc.m4')
-rw-r--r--gl/m4/realloc.m4153
1 files changed, 107 insertions, 46 deletions
diff --git a/gl/m4/realloc.m4 b/gl/m4/realloc.m4
index eb90d588..67c1476b 100644
--- a/gl/m4/realloc.m4
+++ b/gl/m4/realloc.m4
@@ -1,54 +1,22 @@
1# realloc.m4 1# realloc.m4
2# serial 29 2# serial 39.1
3dnl Copyright (C) 2007, 2009-2024 Free Software Foundation, Inc. 3dnl Copyright (C) 2007, 2009-2025 Free Software Foundation, Inc.
4dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved. 6dnl with or without modifications, as long as this notice is preserved.
7dnl This file is offered as-is, without any warranty.
7 8
8# This is adapted with modifications from upstream Autoconf here: 9# An an experimental option, the user can request a sanitized realloc()
9# https://git.savannah.gnu.org/cgit/autoconf.git/tree/lib/autoconf/functions.m4?id=v2.70#n1455 10# implementation, i.e. one that aborts upon undefined behaviour,
10AC_DEFUN([_AC_FUNC_REALLOC_IF], 11# by setting
12# gl_cv_func_realloc_sanitize=yes
13# at configure time.
14AC_DEFUN([gl_FUNC_REALLOC_SANITIZED],
11[ 15[
12 AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles 16 AC_CACHE_CHECK([whether realloc should abort upon undefined behaviour],
13 AC_CACHE_CHECK([whether realloc (0, 0) returns nonnull], 17 [gl_cv_func_realloc_sanitize],
14 [ac_cv_func_realloc_0_nonnull], 18 [test -n "$gl_cv_func_realloc_sanitize" || gl_cv_func_realloc_sanitize=no])
15 [AC_RUN_IFELSE( 19])
16 [AC_LANG_PROGRAM(
17 [[#include <stdlib.h>
18 ]],
19 [[void *p = realloc (0, 0);
20 void * volatile vp = p;
21 int result = !vp;
22 free (p);
23 return result;]])
24 ],
25 [ac_cv_func_realloc_0_nonnull=yes],
26 [ac_cv_func_realloc_0_nonnull=no],
27 [case "$host_os" in
28 # Guess yes on platforms where we know the result.
29 *-gnu* | freebsd* | netbsd* | openbsd* | bitrig* \
30 | gnu* | *-musl* | midipix* | midnightbsd* \
31 | hpux* | solaris* | cygwin* | mingw* | windows* | msys* )
32 ac_cv_func_realloc_0_nonnull="guessing yes" ;;
33 # If we don't know, obey --enable-cross-guesses.
34 *) ac_cv_func_realloc_0_nonnull="$gl_cross_guess_normal" ;;
35 esac
36 ])
37 ])
38 AS_CASE([$ac_cv_func_realloc_0_nonnull], [*yes], [$1], [$2])
39])# AC_FUNC_REALLOC
40
41# gl_FUNC_REALLOC_GNU
42# -------------------
43# Replace realloc if it is not compatible with GNU libc.
44AC_DEFUN([gl_FUNC_REALLOC_GNU],
45[
46 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
47 AC_REQUIRE([gl_FUNC_REALLOC_POSIX])
48 if test $REPLACE_REALLOC_FOR_REALLOC_GNU = 0; then
49 _AC_FUNC_REALLOC_IF([], [REPLACE_REALLOC_FOR_REALLOC_GNU=1])
50 fi
51])# gl_FUNC_REALLOC_GNU
52 20
53# gl_FUNC_REALLOC_POSIX 21# gl_FUNC_REALLOC_POSIX
54# --------------------- 22# ---------------------
@@ -59,7 +27,100 @@ AC_DEFUN([gl_FUNC_REALLOC_POSIX],
59[ 27[
60 AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) 28 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
61 AC_REQUIRE([gl_FUNC_MALLOC_POSIX]) 29 AC_REQUIRE([gl_FUNC_MALLOC_POSIX])
62 if test $REPLACE_MALLOC_FOR_MALLOC_POSIX = 1; then 30 AC_REQUIRE([AC_CANONICAL_HOST])
31 AC_CACHE_CHECK([whether realloc sets errno on failure],
32 [gl_cv_func_realloc_posix],
33 [
34 dnl FreeBSD 15.0 realloc() does not set errno when asked for more than
35 dnl 0x7000000000000000 bytes.
36 case "$host_os" in
37 darwin* | freebsd* | dragonfly* | midnightbsd* | netbsd* | openbsd*)
38 AC_RUN_IFELSE(
39 [AC_LANG_SOURCE(
40 [[#include <errno.h>
41 #include <stdlib.h>
42 int main (int argc, char **argv)
43 {
44 void *p;
45 errno = 1729;
46 p = realloc (malloc (1), (size_t)(-1) / 100 * 49);
47 return (!p && errno == 1729);
48 }
49 ]])
50 ],
51 [gl_cv_func_realloc_posix=yes],
52 [gl_cv_func_realloc_posix=no],
53 [case "$host_os" in
54 freebsd*) gl_cv_func_realloc_posix="guessing no" ;;
55 *) gl_cv_func_realloc_posix="guessing yes" ;;
56 esac
57 ])
58 ;;
59 *)
60 gl_cv_func_realloc_posix="$gl_cv_func_malloc_posix"
61 ;;
62 esac
63 ])
64 case "$gl_cv_func_realloc_posix" in
65 *yes)
66 AC_DEFINE([HAVE_REALLOC_POSIX], [1],
67 [Define if realloc sets errno on allocation failure.])
68 ;;
69 *)
70 REPLACE_REALLOC_FOR_REALLOC_POSIX=1
71 ;;
72 esac
73 AC_REQUIRE([gl_FUNC_REALLOC_SANITIZED])
74 if test "$gl_cv_func_realloc_sanitize" != no; then
63 REPLACE_REALLOC_FOR_REALLOC_POSIX=1 75 REPLACE_REALLOC_FOR_REALLOC_POSIX=1
76 AC_DEFINE([NEED_SANITIZED_REALLOC], [1],
77 [Define to 1 if realloc should abort upon undefined behaviour.])
64 fi 78 fi
65]) 79])
80
81# gl_FUNC_REALLOC_0_NONNULL
82# -------------------------
83# Replace realloc if realloc (..., 0) returns null.
84# Modules that use this macro directly or indirectly should depend
85# on extensions-aix, so that _LINUX_SOURCE_COMPAT gets defined
86# before this macro gets invoked. This helps if !(__VEC__ || __AIXVEC),
87# and doesn't hurt otherwise.
88AC_DEFUN([gl_FUNC_REALLOC_0_NONNULL],
89[
90 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
91 AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
92 AC_REQUIRE([gl_FUNC_REALLOC_POSIX])
93 AC_CACHE_CHECK([whether realloc (..., 0) returns nonnull],
94 [gl_cv_func_realloc_0_nonnull],
95 [AC_RUN_IFELSE(
96 [AC_LANG_PROGRAM(
97 [[#include <stdlib.h>
98 /* Use prealloc to test; "volatile" prevents the compiler
99 from optimizing the realloc call away. */
100 void *(*volatile prealloc) (void *, size_t) = realloc;]],
101 [[void *p = prealloc (0, 0);
102 int result = !p;
103 p = prealloc (p, 0);
104 result |= !p;
105 free (p);
106 return result;]])],
107 [gl_cv_func_realloc_0_nonnull=yes],
108 [gl_cv_func_realloc_0_nonnull=no],
109 [AS_CASE([$host_os],
110 [# Guess yes on platforms where we know the result.
111 freebsd* | netbsd* | openbsd* | darwin* | bitrig* \
112 | *-musl* | midipix* | midnightbsd* \
113 | hpux* | solaris* | cygwin*],
114 [gl_cv_func_realloc_0_nonnull="guessing yes"],
115 [# Guess as follows if we don't know.
116 gl_cv_func_realloc_0_nonnull=$gl_cross_guess_normal])])])
117 AS_CASE([$gl_cv_func_realloc_0_nonnull],
118 [*yes],
119 [AC_DEFINE([HAVE_REALLOC_0_NONNULL], [1],
120 [Define to 1 if realloc (..., 0) returns nonnull.])],
121 [AS_CASE([$gl_cv_func_realloc_sanitize,$gl_cv_malloc_ptrdiff,$gl_cv_func_malloc_posix,$host],
122 [yes,*,*,* | *,no,*,* | *,*,*no,* | *,*,*,aarch64c-*-freebsd*],
123 [REPLACE_REALLOC_FOR_REALLOC_POSIX=1],
124 [# Optimize for common case of glibc 2.1.1+ and compatibles.
125 REPLACE_REALLOC_FOR_REALLOC_POSIX=2])])
126])