diff options
Diffstat (limited to 'gl/calloc.c')
| -rw-r--r-- | gl/calloc.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/gl/calloc.c b/gl/calloc.c index 81dfd3ef..5258c5de 100644 --- a/gl/calloc.c +++ b/gl/calloc.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* calloc() function that is glibc compatible. | 1 | /* calloc() function that is glibc compatible. |
| 2 | This wrapper function is required at least on Tru64 UNIX 5.1 and mingw. | 2 | This wrapper function is required at least on Tru64 UNIX 5.1 and mingw. |
| 3 | Copyright (C) 2004-2007, 2009-2024 Free Software Foundation, Inc. | 3 | Copyright (C) 2004-2007, 2009-2025 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 |
| @@ -17,17 +17,15 @@ | |||
| 17 | 17 | ||
| 18 | /* written by Jim Meyering and Bruno Haible */ | 18 | /* written by Jim Meyering and Bruno Haible */ |
| 19 | 19 | ||
| 20 | /* Ensure that we call the system's calloc() below. */ | ||
| 21 | #define _GL_USE_STDLIB_ALLOC 1 | ||
| 20 | #include <config.h> | 22 | #include <config.h> |
| 21 | 23 | ||
| 22 | /* Specification. */ | 24 | /* Specification. */ |
| 23 | #include <stdlib.h> | 25 | #include <stdlib.h> |
| 24 | 26 | ||
| 25 | #include <errno.h> | 27 | #include <errno.h> |
| 26 | 28 | #include <stdckdint.h> | |
| 27 | #include "xalloc-oversized.h" | ||
| 28 | |||
| 29 | /* Call the system's calloc below. */ | ||
| 30 | #undef calloc | ||
| 31 | 29 | ||
| 32 | /* Allocate and zero-fill an NxS-byte block of memory from the heap, | 30 | /* Allocate and zero-fill an NxS-byte block of memory from the heap, |
| 33 | even if N or S is zero. */ | 31 | even if N or S is zero. */ |
| @@ -35,14 +33,19 @@ | |||
| 35 | void * | 33 | void * |
| 36 | rpl_calloc (size_t n, size_t s) | 34 | rpl_calloc (size_t n, size_t s) |
| 37 | { | 35 | { |
| 36 | #if !HAVE_MALLOC_0_NONNULL | ||
| 38 | if (n == 0 || s == 0) | 37 | if (n == 0 || s == 0) |
| 39 | n = s = 1; | 38 | n = s = 1; |
| 39 | #endif | ||
| 40 | 40 | ||
| 41 | if (xalloc_oversized (n, s)) | 41 | #if !HAVE_MALLOC_PTRDIFF |
| 42 | ptrdiff_t signed_n; | ||
| 43 | if (ckd_mul (&signed_n, n, s)) | ||
| 42 | { | 44 | { |
| 43 | errno = ENOMEM; | 45 | errno = ENOMEM; |
| 44 | return NULL; | 46 | return NULL; |
| 45 | } | 47 | } |
| 48 | #endif | ||
| 46 | 49 | ||
| 47 | void *result = calloc (n, s); | 50 | void *result = calloc (n, s); |
| 48 | 51 | ||
