]> Savannah Git Hosting - gnulib.git/commitdiff
alignalloc: Take advantage of CHERI bounds-checking.
authorBruno Haible <bruno@clisp.org>
Sat, 11 Nov 2023 18:28:26 +0000 (19:28 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 11 Nov 2023 18:28:26 +0000 (19:28 +0100)
* lib/alignalloc.h: Include <cheri.h>.
(alignalloc): When size is 0, return a pointer whose bounds are of
size 0, not 1.

ChangeLog
lib/alignalloc.h

index 3ed337f6913d66ffeff7ac3ccf46423a8f23ea5e..b0f6f9f40422d9f11c77689974175bbbf6478321 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2023-11-11  Bruno Haible  <bruno@clisp.org>
+
+       alignalloc: Take advantage of CHERI bounds-checking.
+       * lib/alignalloc.h: Include <cheri.h>.
+       (alignalloc): When size is 0, return a pointer whose bounds are of
+       size 0, not 1.
+
 2023-11-11  Bruno Haible  <bruno@clisp.org>
 
        rawmemchr tests: Add test case for last commit.
index 6a01aacb4f493fe29b4115ac9888192fe220196d..cb40b344e8f59c6583be0a6e31ed7a5e99ddd253 100644 (file)
@@ -29,6 +29,9 @@
 #include <errno.h>
 #include <stdlib.h>
 #include "idx.h"
+#if defined __CHERI__
+# include <cheri.h>
+#endif
 
 _GL_INLINE_HEADER_BEGIN
 #ifndef ALIGNALLOC_INLINE
@@ -93,6 +96,10 @@ alignalloc (idx_t alignment, idx_t size)
   if (alignment < sizeof (void *))
     alignment = sizeof (void *);
   errno = posix_memalign (&ptr, alignment, size | !size);
+#  if defined __CHERI__
+  if (ptr != NULL)
+    ptr = cheri_bounds_set (ptr, size);
+#  endif
   return ptr;
 # endif
 }