bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH 1/3] posix_memalign-tests: port to CHERI-64


From: Paul Eggert
Subject: [PATCH 1/3] posix_memalign-tests: port to CHERI-64
Date: Mon, 6 Nov 2023 23:59:59 -0800

* tests/test-posix_memalign.c (main):
Don’t assume sizeof (void *) <= 8.
---
 ChangeLog                   |  4 ++++
 tests/test-posix_memalign.c | 14 +++++++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d322f9a08e..7f02c24f6c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2023-11-06  Paul Eggert  <eggert@cs.ucla.edu>
 
+       posix_memalign-tests: port to CHERI-64
+       * tests/test-posix_memalign.c (main):
+       Don’t assume sizeof (void *) <= 8.
+
        mcel-tests: fix read overrun in test case
        * tests/test-mcel.c (main): Don’t overrun test input buffer.
        Problem reported by Bruno Haible; found on CHERI-64.
diff --git a/tests/test-posix_memalign.c b/tests/test-posix_memalign.c
index f0c91fbd9d..377d1c2733 100644
--- a/tests/test-posix_memalign.c
+++ b/tests/test-posix_memalign.c
@@ -62,10 +62,13 @@ main (int argc, char *argv[])
           memset (aligned4_blocks[i], 'v', size);
         }
 
-      ASSERT (posix_memalign (&aligned8_blocks[i], 8, size) == 0);
-      ASSERT (aligned8_blocks[i] != NULL);
-      ASSERT (((uintptr_t) aligned8_blocks[i] % 8) == 0);
-      memset (aligned8_blocks[i], 'w', size);
+      if (sizeof (void *) <= 8)
+       {
+         ASSERT (posix_memalign (&aligned8_blocks[i], 8, size) == 0);
+         ASSERT (aligned8_blocks[i] != NULL);
+         ASSERT (((uintptr_t) aligned8_blocks[i] % 8) == 0);
+         memset (aligned8_blocks[i], 'w', size);
+       }
 
       ASSERT (posix_memalign (&aligned16_blocks[i], 16, size) == 0);
       ASSERT (aligned16_blocks[i] != NULL);
@@ -89,7 +92,8 @@ main (int argc, char *argv[])
         free (aligned2_blocks[i]);
       if (sizeof (void *) <= 4)
         free (aligned4_blocks[i]);
-      free (aligned8_blocks[i]);
+      if (sizeof (void *) <= 8)
+       free (aligned8_blocks[i]);
       free (aligned16_blocks[i]);
       free (aligned32_blocks[i]);
       free (aligned64_blocks[i]);
-- 
2.39.2




reply via email to

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