diff options
Diffstat (limited to 'gl/malloc.c')
| -rw-r--r-- | gl/malloc.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/gl/malloc.c b/gl/malloc.c index 2a7867a1..5642c83c 100644 --- a/gl/malloc.c +++ b/gl/malloc.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* malloc() function that is glibc compatible. | 1 | /* malloc() function that is glibc compatible. |
| 2 | 2 | ||
| 3 | Copyright (C) 1997-1998, 2006-2007, 2009-2024 Free Software Foundation, Inc. | 3 | Copyright (C) 1997-1998, 2006-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,28 +17,33 @@ | |||
| 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 malloc() below. */ | ||
| 20 | #define _GL_USE_STDLIB_ALLOC 1 | 21 | #define _GL_USE_STDLIB_ALLOC 1 |
| 21 | #include <config.h> | 22 | #include <config.h> |
| 22 | 23 | ||
| 23 | #include <stdlib.h> | 24 | #include <stdlib.h> |
| 24 | 25 | ||
| 25 | #include <errno.h> | 26 | #include <errno.h> |
| 26 | 27 | #include <stdckdint.h> | |
| 27 | #include "xalloc-oversized.h" | ||
| 28 | 28 | ||
| 29 | /* Allocate an N-byte block of memory from the heap, even if N is 0. */ | 29 | /* Allocate an N-byte block of memory from the heap, even if N is 0. */ |
| 30 | 30 | ||
| 31 | void * | 31 | void * |
| 32 | rpl_malloc (size_t n) | 32 | rpl_malloc (size_t n) |
| 33 | { | 33 | { |
| 34 | #if !HAVE_MALLOC_0_NONNULL | ||
| 34 | if (n == 0) | 35 | if (n == 0) |
| 35 | n = 1; | 36 | n = 1; |
| 37 | #endif | ||
| 36 | 38 | ||
| 37 | if (xalloc_oversized (n, 1)) | 39 | #if !HAVE_MALLOC_PTRDIFF |
| 40 | ptrdiff_t signed_n; | ||
| 41 | if (ckd_add (&signed_n, n, 0)) | ||
| 38 | { | 42 | { |
| 39 | errno = ENOMEM; | 43 | errno = ENOMEM; |
| 40 | return NULL; | 44 | return NULL; |
| 41 | } | 45 | } |
| 46 | #endif | ||
| 42 | 47 | ||
| 43 | void *result = malloc (n); | 48 | void *result = malloc (n); |
| 44 | 49 | ||
