bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/2] rawmemchr: port better to CHERI


From: Bruno Haible
Subject: Re: [PATCH 2/2] rawmemchr: port better to CHERI
Date: Sat, 11 Nov 2023 11:47:40 +0100

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  <bruno@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

[Prev in Thread] Current Thread [Next in Thread]