]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Fix use of $3 in _AC_FUNC_MALLOC_IF etc
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 1 Nov 2024 01:29:54 +0000 (18:29 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 1 Nov 2024 02:01:05 +0000 (19:01 -0700)
Use m4_default in case $3 is omitted.
Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2024-10/msg00284.html
Also, use AS_CASE to defend against $3 containing macros
that might be expaned.

lib/autoconf/functions.m4

index c12e198774f4838f52f525fb452b1d7f8b7d89f2..9d5f5bb8c91049ef58b936196e70d676938e7e93 100644 (file)
@@ -968,11 +968,11 @@ fi
 ])
 
 
-# _AC_FUNC_MALLOC_IF(IF-WORKS, IF-NOT, UNKNOWN-ASSUME)
-# ----------------------------------------------------
+# _AC_FUNC_MALLOC_IF(IF-WORKS, IF-NOT[, UNKNOWN-ASSUME])
+# ------------------------------------------------------
 # If 'malloc (0, 0)' returns nonnull, run IF-WORKS, otherwise, IF-NOT.
 # If it is not known whether it works, assume the shell word UNKNOWN-ASSUME,
-# which should end in "yes" or in something else.
+# which should end in "yes" or in something else (the latter is the default).
 AC_DEFUN([_AC_FUNC_MALLOC_IF],
 [
   AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
@@ -987,21 +987,17 @@ AC_DEFUN([_AC_FUNC_MALLOC_IF],
           [[void *p = pmalloc (0);
             int result = !p;
             free (p);
-            return result;]])
-       ],
+            return result;]])],
        [ac_cv_func_malloc_0_nonnull=yes],
        [ac_cv_func_malloc_0_nonnull=no],
-       [case "$host_os" in
-          # Guess yes on platforms where we know the result.
-          *-gnu* | freebsd* | netbsd* | openbsd* | bitrig* \
-          | gnu* | *-musl* | midipix* | midnightbsd* \
-          | hpux* | solaris* | cygwin* | mingw* | windows* | msys* )
-            ac_cv_func_malloc_0_nonnull="guessing yes" ;;
-          # Guess as follows if we don't know.
-          *) ac_cv_func_malloc_0_nonnull=$3 ;;
-        esac
-       ])
-    ])
+       [AS_CASE([$host_os],
+          [# Guess yes on platforms where we know the result.
+           *-gnu* | freebsd* | netbsd* | openbsd* | bitrig* \
+           | gnu* | *-musl* | midipix* | midnightbsd* \
+           | hpux* | solaris* | cygwin* | mingw* | windows* | msys*],
+            [ac_cv_func_malloc_0_nonnull="guessing yes"],
+          [# Guess as follows if we don't know.
+           ac_cv_func_malloc_0_nonnull=m4_default([$3], ["guessing no"])])])])
   AS_CASE([$ac_cv_func_malloc_0_nonnull], [*yes], [$1], [$2])
 ])# _AC_FUNC_MALLOC_IF
 
@@ -1484,11 +1480,11 @@ AU_ALIAS([AM_FUNC_OBSTACK], [AC_FUNC_OBSTACK])
 
 
 
-# _AC_FUNC_REALLOC_IF(IF-WORKS, IF-NOT, UNKNOWN-ASSUME)
-# -----------------------------------------------------
+# _AC_FUNC_REALLOC_IF(IF-WORKS, IF-NOT[, UNKNOWN-ASSUME])
+# -------------------------------------------------------
 # If 'realloc (0, 0)' returns nonnull, run IF-WORKS, otherwise, IF-NOT.
 # If it is not known whether it works, assume the shell word UNKNOWN-ASSUME,
-# which should end in "yes" or in something else.
+# which should end in "yes" or in something else (the latter is the default).
 AC_DEFUN([_AC_FUNC_REALLOC_IF],
 [
   AC_REQUIRE([AC_CANONICAL_HOST])dnl for cross-compiles
@@ -1503,21 +1499,17 @@ AC_DEFUN([_AC_FUNC_REALLOC_IF],
           [[void *p = prealloc (0, 0);
             int result = !p;
             free (p);
-            return result;]])
-       ],
+            return result;]])],
        [ac_cv_func_realloc_0_nonnull=yes],
        [ac_cv_func_realloc_0_nonnull=no],
-       [case "$host_os" in
-          # Guess yes on platforms where we know the result.
-          *-gnu* | freebsd* | netbsd* | openbsd* | bitrig* \
-          | gnu* | *-musl* | midipix* | midnightbsd* \
-          | hpux* | solaris* | cygwin* | mingw* | windows* | msys* )
-            ac_cv_func_realloc_0_nonnull="guessing yes" ;;
-          # Guess as follows if we don't know.
-          *) ac_cv_func_realloc_0_nonnull=$3 ;;
-        esac
-       ])
-    ])
+       [AS_CASE([$host_os],
+          [# Guess yes on platforms where we know the result.
+           *-gnu* | freebsd* | netbsd* | openbsd* | bitrig* \
+           | gnu* | *-musl* | midipix* | midnightbsd* \
+           | hpux* | solaris* | cygwin* | mingw* | windows* | msys*],
+            [ac_cv_func_realloc_0_nonnull="guessing yes"],
+          [# Guess as follows if we don't know.
+           ac_cv_func_realloc_0_nonnull=m4_default([$3], ["guessing no"])])])])
   AS_CASE([$ac_cv_func_realloc_0_nonnull], [*yes], [$1], [$2])
 ])# _AC_FUNC_REALLOC_IF