* lib/eealloc.h: Include <cheri.h>.
(eemalloc): When n is 0, return a pointer whose bounds are of size 0,
not 1.
(eerealloc): Likewise.
+2023-11-11 Bruno Haible <bruno@clisp.org>
+
+ eealloc: Take advantage of CHERI bounds-checking.
+ * lib/eealloc.h: Include <cheri.h>.
+ (eemalloc): When n is 0, return a pointer whose bounds are of size 0,
+ not 1.
+ (eerealloc): Likewise.
+
2023-11-11 Bruno Haible <bruno@clisp.org>
alignalloc: Take advantage of CHERI bounds-checking.
#endif
#include <stdlib.h>
+#if defined __CHERI__
+# include <cheri.h>
+#endif
_GL_INLINE_HEADER_BEGIN
#ifndef EEALLOC_INLINE
eemalloc (size_t n)
{
/* If n is zero, allocate a 1-byte block. */
+ size_t nx = n;
if (n == 0)
- n = 1;
- return malloc (n);
+ nx = 1;
+ void *ptr = malloc (nx);
+# if defined __CHERI__
+ if (ptr != NULL)
+ ptr = cheri_bounds_set (ptr, n);
+# endif
+ return ptr;
}
#endif
eerealloc (void *p, size_t n)
{
/* If n is zero, allocate or keep a 1-byte block. */
+ size_t nx = n;
if (n == 0)
- n = 1;
- return realloc (p, n);
+ nx = 1;
+ void *ptr = realloc (p, nx);
+# if defined __CHERI__
+ if (ptr != NULL)
+ ptr = cheri_bounds_set (ptr, n);
+# endif
+ return ptr;
}
#endif