diff options
| author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-12-28 12:13:40 +0100 |
|---|---|---|
| committer | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-12-28 12:13:40 +0100 |
| commit | b0afb8fe0ff1d87165af9df61501197a06240dda (patch) | |
| tree | 274ac6a96c53ef4c19ab4974ce24a06a233128c5 /gl/ialloc.h | |
| parent | 68fc05381ee5fa0aee1413118fbb3d81ca888b09 (diff) | |
| download | monitoring-plugins-b0afb8fe0ff1d87165af9df61501197a06240dda.tar.gz | |
Sync with Gnulib stable-202507 code (a8ac9f9ce5)
Diffstat (limited to 'gl/ialloc.h')
| -rw-r--r-- | gl/ialloc.h | 39 |
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 | |||
| 68 | void * | 65 | void * |
| 69 | irealloc (void *p, idx_t s) | 66 | irealloc (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) | |||
| 112 | IALLOC_INLINE void * | 97 | IALLOC_INLINE void * |
| 113 | ireallocarray (void *p, idx_t n, idx_t s) | 98 | ireallocarray (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 |
