diff options
Diffstat (limited to 'gl/m4/malloc.m4')
| -rw-r--r-- | gl/m4/malloc.m4 | 58 |
1 files changed, 30 insertions, 28 deletions
diff --git a/gl/m4/malloc.m4 b/gl/m4/malloc.m4 index 547b4e4d..a95e33db 100644 --- a/gl/m4/malloc.m4 +++ b/gl/m4/malloc.m4 | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | # malloc.m4 | 1 | # malloc.m4 |
| 2 | # serial 43.1 | 2 | # serial 46 |
| 3 | dnl Copyright (C) 2007, 2009-2025 Free Software Foundation, Inc. | 3 | dnl Copyright (C) 2007, 2009-2026 Free Software Foundation, Inc. |
| 4 | dnl This file is free software; the Free Software Foundation | 4 | dnl This file is free software; the Free Software Foundation |
| 5 | dnl gives unlimited permission to copy and/or distribute it, | 5 | dnl gives unlimited permission to copy and/or distribute it, |
| 6 | dnl with or without modifications, as long as this notice is preserved. | 6 | dnl with or without modifications, as long as this notice is preserved. |
| @@ -187,40 +187,42 @@ AC_DEFUN([gl_CHECK_MALLOC_POSIX], | |||
| 187 | [gl_cv_func_malloc_posix="guessing yes"], | 187 | [gl_cv_func_malloc_posix="guessing yes"], |
| 188 | [gl_cv_func_malloc_posix="guessing no"]) | 188 | [gl_cv_func_malloc_posix="guessing no"]) |
| 189 | ;; | 189 | ;; |
| 190 | irix* | solaris*) | 190 | solaris*) |
| 191 | dnl On IRIX 6.5, the three functions return NULL with errno unset | 191 | dnl On Solaris 11.3, the three functions might fail with errno set |
| 192 | dnl when the argument is larger than PTRDIFF_MAX. | ||
| 193 | dnl On Solaris 11.3, the three functions return NULL with errno set | ||
| 194 | dnl to EAGAIN, not ENOMEM, when the argument is larger than | 192 | dnl to EAGAIN, not ENOMEM, when the argument is larger than |
| 195 | dnl PTRDIFF_MAX. | 193 | dnl PTRDIFF_MAX. See: |
| 194 | dnl https://lists.gnu.org/r/bug-gnulib/2021-05/msg00052.html | ||
| 196 | dnl Here is a test program: | 195 | dnl Here is a test program: |
| 196 | |||
| 197 | m4_divert_push([KILL]) | 197 | m4_divert_push([KILL]) |
| 198 | #include <errno.h> | 198 | #include <errno.h> |
| 199 | #include <stddef.h> | ||
| 199 | #include <stdio.h> | 200 | #include <stdio.h> |
| 201 | #include <stdint.h> | ||
| 200 | #include <stdlib.h> | 202 | #include <stdlib.h> |
| 201 | #define ptrdiff_t long | ||
| 202 | #ifndef PTRDIFF_MAX | ||
| 203 | # define PTRDIFF_MAX ((ptrdiff_t) ((1UL << (8 * sizeof (ptrdiff_t) - 1)) - 1)) | ||
| 204 | #endif | ||
| 205 | 203 | ||
| 206 | int main () | 204 | #define TEST_CALL(call) \ |
| 205 | do { \ | ||
| 206 | void *p = call; \ | ||
| 207 | if (p) \ | ||
| 208 | fprintf (stderr, "returned %p (incorrect success)\n", p); \ | ||
| 209 | else if (errno == ENOMEM) \ | ||
| 210 | perror ("correct failure"); \ | ||
| 211 | else \ | ||
| 212 | perror ("incorrect failure (wrong errno)"); \ | ||
| 213 | free (p); \ | ||
| 214 | } while (0) | ||
| 215 | |||
| 216 | int | ||
| 217 | main () | ||
| 207 | { | 218 | { |
| 208 | void *p; | 219 | size_t big = PTRDIFF_MAX; |
| 209 | 220 | TEST_CALL (malloc (big + 1)); | |
| 210 | fprintf (stderr, "PTRDIFF_MAX = %lu\n", (unsigned long) PTRDIFF_MAX); | 221 | TEST_CALL (calloc (big / 2 + 1, 2)); |
| 211 | 222 | TEST_CALL (realloc (NULL, big + 1)); | |
| 212 | errno = 0; | 223 | void *small = malloc (1); |
| 213 | p = malloc ((unsigned long) PTRDIFF_MAX + 1); | 224 | TEST_CALL (realloc (small, big + 1)); |
| 214 | fprintf (stderr, "p=%p errno=%d\n", p, errno); | 225 | free (small); |
| 215 | |||
| 216 | errno = 0; | ||
| 217 | p = calloc (PTRDIFF_MAX / 2 + 1, 2); | ||
| 218 | fprintf (stderr, "p=%p errno=%d\n", p, errno); | ||
| 219 | |||
| 220 | errno = 0; | ||
| 221 | p = realloc (NULL, (unsigned long) PTRDIFF_MAX + 1); | ||
| 222 | fprintf (stderr, "p=%p errno=%d\n", p, errno); | ||
| 223 | |||
| 224 | return 0; | 226 | return 0; |
| 225 | } | 227 | } |
| 226 | m4_divert_pop([KILL]) | 228 | m4_divert_pop([KILL]) |
