1 /* ialloc.h -- malloc with idx_t rather than size_t
3 Copyright 2021 Free Software Foundation, Inc.
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
7 published by the Free Software Foundation; either version 3 of the
8 License, or (at your option) any later version.
10 This file is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
27 #ifndef _GL_INLINE_HEADER_BEGIN
28 #error "Please include config.h first."
30 _GL_INLINE_HEADER_BEGIN
32 # define IALLOC_INLINE _GL_INLINE
39 IALLOC_INLINE void * _GL_ATTRIBUTE_COLD
40 _gl_alloc_nomem (void)
49 return s <= SIZE_MAX ? malloc (s) : _gl_alloc_nomem ();
53 irealloc (void *p, idx_t s)
55 /* Work around GNU realloc glitch by treating a zero size as if it
56 were 1, so that returning NULL is equivalent to failing. */
57 return s <= SIZE_MAX ? realloc (p, s | !s) : _gl_alloc_nomem ();
61 icalloc (idx_t n, idx_t s)
66 return _gl_alloc_nomem ();
72 return _gl_alloc_nomem ();
79 ireallocarray (void *p, idx_t n, idx_t s)
81 /* Work around GNU reallocarray glitch by treating a zero size as if
82 it were 1, so that returning NULL is equivalent to failing. */
85 return (n <= SIZE_MAX && s <= SIZE_MAX
86 ? reallocarray (p, n, s)
87 : _gl_alloc_nomem ());