From: Bruno Haible Date: Sat, 11 Nov 2023 18:28:26 +0000 (+0100) Subject: alignalloc: Take advantage of CHERI bounds-checking. X-Git-Tag: v1.0~602 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=dba81b1764b575d119fd2ee86f386d461e83be76;p=gnulib.git alignalloc: Take advantage of CHERI bounds-checking. * lib/alignalloc.h: Include . (alignalloc): When size is 0, return a pointer whose bounds are of size 0, not 1. --- diff --git a/ChangeLog b/ChangeLog index 3ed337f691..b0f6f9f404 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2023-11-11 Bruno Haible + + alignalloc: Take advantage of CHERI bounds-checking. + * lib/alignalloc.h: Include . + (alignalloc): When size is 0, return a pointer whose bounds are of + size 0, not 1. + 2023-11-11 Bruno Haible rawmemchr tests: Add test case for last commit. diff --git a/lib/alignalloc.h b/lib/alignalloc.h index 6a01aacb4f..cb40b344e8 100644 --- a/lib/alignalloc.h +++ b/lib/alignalloc.h @@ -29,6 +29,9 @@ #include #include #include "idx.h" +#if defined __CHERI__ +# include +#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 }