summaryrefslogtreecommitdiffstats
path: root/gl/ialloc.h
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-12-28 12:50:39 +0100
committerGitHub <noreply@github.com>2025-12-28 12:50:39 +0100
commite7dd07c8025b169b7b43b955066a7200d9cdf244 (patch)
tree6e8c927cfc67f3708b91ac79df07707af26e4929 /gl/ialloc.h
parent828a9720b10814c5836d03aa35af05d196c4104b (diff)
parentb0afb8fe0ff1d87165af9df61501197a06240dda (diff)
downloadmonitoring-plugins-e7dd07c8025b169b7b43b955066a7200d9cdf244.tar.gz
Merge pull request #2213 from RincewindsHat/update/gnulib
Sync with Gnulib stable-202507 code (a8ac9f9ce5)
Diffstat (limited to 'gl/ialloc.h')
-rw-r--r--gl/ialloc.h39
1 files changed, 5 insertions, 34 deletions
diff --git a/gl/ialloc.h b/gl/ialloc.h
index 2aa94ae7..8bf5dd12 100644
--- a/gl/ialloc.h
+++ b/gl/ialloc.h
@@ -1,6 +1,6 @@
1/* ialloc.h -- malloc with idx_t rather than size_t 1/* ialloc.h -- malloc with idx_t rather than size_t
2 2
3 Copyright 2021-2024 Free Software Foundation, Inc. 3 Copyright 2021-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
@@ -29,9 +29,6 @@
29#include <errno.h> 29#include <errno.h>
30#include <stdint.h> 30#include <stdint.h>
31#include <stdlib.h> 31#include <stdlib.h>
32#if defined __CHERI_PURE_CAPABILITY__
33# include <cheri.h>
34#endif
35 32
36_GL_INLINE_HEADER_BEGIN 33_GL_INLINE_HEADER_BEGIN
37#ifndef IALLOC_INLINE 34#ifndef IALLOC_INLINE
@@ -68,19 +65,7 @@ IALLOC_INLINE
68void * 65void *
69irealloc (void *p, idx_t s) 66irealloc (void *p, idx_t s)
70{ 67{
71 if (s <= SIZE_MAX) 68 return s <= SIZE_MAX ? realloc (p, s) : _gl_alloc_nomem ();
72 {
73 /* Work around GNU realloc glitch by treating a zero size as if it
74 were 1, so that returning NULL is equivalent to failing. */
75 p = realloc (p, s | !s);
76#if defined __CHERI_PURE_CAPABILITY__
77 if (p != NULL)
78 p = cheri_bounds_set (p, s);
79#endif
80 return p;
81 }
82 else
83 return _gl_alloc_nomem ();
84} 69}
85 70
86/* icalloc (num, size) is like calloc (num, size). 71/* icalloc (num, size) is like calloc (num, size).
@@ -112,23 +97,9 @@ icalloc (idx_t n, idx_t s)
112IALLOC_INLINE void * 97IALLOC_INLINE void *
113ireallocarray (void *p, idx_t n, idx_t s) 98ireallocarray (void *p, idx_t n, idx_t s)
114{ 99{
115 if (n <= SIZE_MAX && s <= SIZE_MAX) 100 return (n <= SIZE_MAX && s <= SIZE_MAX
116 { 101 ? reallocarray (p, n, s)
117 /* Work around GNU reallocarray glitch by treating a zero size as if 102 : _gl_alloc_nomem ());
118 it were 1, so that returning NULL is equivalent to failing. */
119 size_t nx = n;
120 size_t sx = s;
121 if (n == 0 || s == 0)
122 nx = sx = 1;
123 p = reallocarray (p, nx, sx);
124#if defined __CHERI_PURE_CAPABILITY__
125 if (p != NULL && (n == 0 || s == 0))
126 p = cheri_bounds_set (p, 0);
127#endif
128 return p;
129 }
130 else
131 return _gl_alloc_nomem ();
132} 103}
133 104
134#ifdef __cplusplus 105#ifdef __cplusplus