From 5f59a34ab747dde8ede7357f3431bf06bd6002fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sun, 8 Mar 2026 17:28:33 +0100 Subject: New upstream version 1.4.2 --- gnulib-m4/malloc.m4 | 65 ++++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 30 deletions(-) (limited to 'gnulib-m4/malloc.m4') diff --git a/gnulib-m4/malloc.m4 b/gnulib-m4/malloc.m4 index 688594fe..a95e33db 100644 --- a/gnulib-m4/malloc.m4 +++ b/gnulib-m4/malloc.m4 @@ -1,6 +1,6 @@ # malloc.m4 -# serial 44 -dnl Copyright (C) 2007, 2009-2025 Free Software Foundation, Inc. +# serial 46 +dnl Copyright (C) 2007, 2009-2026 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -99,7 +99,7 @@ AC_DEFUN([gl_FUNC_MALLOC_PTRDIFF], [REPLACE_MALLOC_FOR_MALLOC_POSIX=1]) ]) -# Test whether malloc, realloc, calloc refuse to create objects +# Test whether malloc, calloc refuse to create objects # larger than what can be expressed in ptrdiff_t. # Set gl_cv_func_malloc_gnu. AC_DEFUN([gl_CHECK_MALLOC_PTRDIFF], @@ -148,7 +148,7 @@ AC_DEFUN([gl_FUNC_MALLOC_POSIX], case "$gl_cv_func_malloc_posix" in *yes) AC_DEFINE([HAVE_MALLOC_POSIX], [1], - [Define if malloc, realloc, and calloc set errno on allocation failure.]) + [Define if malloc and calloc set errno on allocation failure.]) ;; *) REPLACE_MALLOC_FOR_MALLOC_POSIX=1 @@ -156,19 +156,20 @@ AC_DEFUN([gl_FUNC_MALLOC_POSIX], esac ]) -# Test whether malloc, realloc, calloc set errno to ENOMEM on failure. +# Test whether malloc, calloc set errno to ENOMEM on failure. # Set gl_cv_func_malloc_posix to *yes or *no accordingly. AC_DEFUN([gl_CHECK_MALLOC_POSIX], [ AC_REQUIRE([AC_CANONICAL_HOST]) - AC_CACHE_CHECK([whether malloc, realloc, calloc set errno on failure], + AC_CACHE_CHECK([whether malloc, calloc set errno on failure], [gl_cv_func_malloc_posix], [ dnl It is too dangerous to try to allocate a large amount of memory: dnl some systems go to their knees when you do that. So assume that dnl all Unix implementations of the function set errno on failure, dnl except on those platforms where we have seen 'test-malloc-gnu', - dnl 'test-realloc-posix', 'test-calloc-gnu' fail. + dnl 'test-realloc-posix', 'test-calloc-gnu' fail. For platforms + dnl where only 'test-realloc-posix', see realloc.m4. case "$host_os" in mingw* | windows*) dnl Old MSVCRT from 2001 did not set errno=ENOMEM when malloc failed. @@ -187,37 +188,41 @@ AC_DEFUN([gl_CHECK_MALLOC_POSIX], [gl_cv_func_malloc_posix="guessing no"]) ;; solaris*) - dnl On Solaris 11.3, the three functions return NULL with errno set + dnl On Solaris 11.3, the three functions might fail with errno set dnl to EAGAIN, not ENOMEM, when the argument is larger than - dnl PTRDIFF_MAX. + dnl PTRDIFF_MAX. See: + dnl https://lists.gnu.org/r/bug-gnulib/2021-05/msg00052.html dnl Here is a test program: + m4_divert_push([KILL]) #include +#include #include +#include #include -#define ptrdiff_t long -#ifndef PTRDIFF_MAX -# define PTRDIFF_MAX ((ptrdiff_t) ((1UL << (8 * sizeof (ptrdiff_t) - 1)) - 1)) -#endif -int main () +#define TEST_CALL(call) \ + do { \ + void *p = call; \ + if (p) \ + fprintf (stderr, "returned %p (incorrect success)\n", p); \ + else if (errno == ENOMEM) \ + perror ("correct failure"); \ + else \ + perror ("incorrect failure (wrong errno)"); \ + free (p); \ + } while (0) + +int +main () { - void *p; - - fprintf (stderr, "PTRDIFF_MAX = %lu\n", (unsigned long) PTRDIFF_MAX); - - errno = 0; - p = malloc ((unsigned long) PTRDIFF_MAX + 1); - fprintf (stderr, "p=%p errno=%d\n", p, errno); - - errno = 0; - p = calloc (PTRDIFF_MAX / 2 + 1, 2); - fprintf (stderr, "p=%p errno=%d\n", p, errno); - - errno = 0; - p = realloc (NULL, (unsigned long) PTRDIFF_MAX + 1); - fprintf (stderr, "p=%p errno=%d\n", p, errno); - + size_t big = PTRDIFF_MAX; + TEST_CALL (malloc (big + 1)); + TEST_CALL (calloc (big / 2 + 1, 2)); + TEST_CALL (realloc (NULL, big + 1)); + void *small = malloc (1); + TEST_CALL (realloc (small, big + 1)); + free (small); return 0; } m4_divert_pop([KILL]) -- cgit v1.2.3