Paul Eggert wrote:
> * lib/rawmemchr.c (rawmemchr): Use unsigned char for longword,
> since CHERI doesn’t allow the aligned-word trick to speed up
> performance.

The rawmemchr unit test passed for me, on CHERI. This means we are lacking
a unit test for this situation. I'm adding one:


2023-11-11  Bruno Haible  <br...@clisp.org>

        rawmemchr tests: Add test case for last commit.
        * tests/test-rawmemchr.c (main): Add test case for aligned oversized
        read.

diff --git a/tests/test-rawmemchr.c b/tests/test-rawmemchr.c
index c2f6416e26..e32ff739a4 100644
--- a/tests/test-rawmemchr.c
+++ b/tests/test-rawmemchr.c
@@ -88,5 +88,18 @@ main (void)
 
   free (input);
 
+  /* Test aligned oversized reads, which are allowed on most architectures
+     but not on CHERI.  */
+  {
+    input = malloc (5);
+    memcpy (input, "abcde", 5);
+    ASSERT (RAWMEMCHR (input, 'e') == input + 4);
+    ASSERT (RAWMEMCHR (input + 1, 'e') == input + 4);
+    ASSERT (RAWMEMCHR (input + 2, 'e') == input + 4);
+    ASSERT (RAWMEMCHR (input + 3, 'e') == input + 4);
+    ASSERT (RAWMEMCHR (input + 4, 'e') == input + 4);
+    free (input);
+  }
+
   return 0;
 }




Reply via email to