diff options
| author | Jörg Frings-Fürst <debian@jff.email> | 2026-03-08 17:28:33 +0100 |
|---|---|---|
| committer | Jörg Frings-Fürst <debian@jff.email> | 2026-03-08 17:28:33 +0100 |
| commit | 5f59a34ab747dde8ede7357f3431bf06bd6002fe (patch) | |
| tree | 056a4477fd870d454d5be5868cddab829a47f4d2 /tests/xmalloc.c | |
| parent | 27dae84ed92f1ef0300263091972338d12e78348 (diff) | |
New upstream version 1.4.2upstream/1.4.2upstream
Diffstat (limited to 'tests/xmalloc.c')
| -rw-r--r-- | tests/xmalloc.c | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/tests/xmalloc.c b/tests/xmalloc.c index 8a715807..545beb35 100644 --- a/tests/xmalloc.c +++ b/tests/xmalloc.c @@ -1,6 +1,6 @@ /* xmalloc.c -- malloc with out of memory checking - Copyright (C) 1990-2000, 2002-2006, 2008-2025 Free Software Foundation, Inc. + Copyright (C) 1990-2000, 2002-2006, 2008-2026 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -15,10 +15,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */ -#include <config.h> - #define XALLOC_INLINE _GL_EXTERN_INLINE - +#include <config.h> #include "xalloc.h" #include "ialloc.h" @@ -29,7 +27,13 @@ #include <stdint.h> #include <string.h> -static void * _GL_ATTRIBUTE_PURE +/* Pacify GCC up to at least 15.2, which otherwise would incorrectly + complain about check_nonnull. */ +#if _GL_GNUC_PREREQ (4, 6) +# pragma GCC diagnostic ignored "-Wsuggest-attribute=pure" +#endif + +static void * check_nonnull (void *p) { if (!p) @@ -63,10 +67,7 @@ xcharalloc (size_t n) void * xrealloc (void *p, size_t s) { - void *r = realloc (p, s); - if (!r) - xalloc_die (); - return r; + return check_nonnull (realloc (p, s)); } void * @@ -81,10 +82,7 @@ xirealloc (void *p, idx_t s) void * xreallocarray (void *p, size_t n, size_t s) { - void *r = reallocarray (p, n, s); - if (!r) - xalloc_die (); - return r; + return check_nonnull (reallocarray (p, n, s)); } void * @@ -224,13 +222,13 @@ x2nrealloc (void *p, size_t *pn, size_t s) void * xpalloc (void *pa, idx_t *pn, idx_t n_incr_min, ptrdiff_t n_max, idx_t s) { - idx_t n0 = *pn; - /* The approximate size to use for initial small allocation requests. This is the largest "small" request for the GNU C library malloc. */ enum { DEFAULT_MXFAST = 64 * sizeof (size_t) / 4 }; + idx_t n0 = *pn; + /* If the array is tiny, grow it to about (but no greater than) DEFAULT_MXFAST bytes. Otherwise, grow it by about 50%. Adjust the growth according to three constraints: N_INCR_MIN, |
