]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
Fix strict aliasing violations in memchr etc
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 26 Jul 2026 18:49:42 +0000 (11:49 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 26 Jul 2026 20:49:58 +0000 (13:49 -0700)
Problem and fix reported by Lasse Collin in:
https://lists.gnu.org/r/bug-gnulib/2026-07/msg00172.html
* lib/memchr.c (__memchr), lib/memchr2.c (memchr2):
* lib/memrchr.c (__memrchr), lib/rawmemchr.c (rawmemchr):
* lib/strchrnul.c (strchrnul):
Add _GL_ATTRIBUTE_MAY_ALIAS to the longword typedef.

ChangeLog
lib/memchr.c
lib/memchr2.c
lib/memrchr.c
lib/rawmemchr.c
lib/strchrnul.c

index 8fb1fccc2c1f2c556f3a930df9a40e0005e5e9a8..e74699ea91b680f7eda9cd61b37dc1390debda90 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2026-07-26  Paul Eggert  <eggert@cs.ucla.edu>
 
+       Fix strict aliasing violations in memchr etc
+       Problem and fix reported by Lasse Collin in:
+       https://lists.gnu.org/r/bug-gnulib/2026-07/msg00172.html
+       * lib/memchr.c (__memchr), lib/memchr2.c (memchr2):
+       * lib/memrchr.c (__memrchr), lib/rawmemchr.c (rawmemchr):
+       * lib/strchrnul.c (strchrnul):
+       Add _GL_ATTRIBUTE_MAY_ALIAS to the longword typedef.
+
        snprintf, vsnprintf: update doc
        * doc/gnulib-intro.texi (Supported Platforms):
        Also mention z/OS, Fil-C.  Not sure where they should be listed
index 6adac7e179e3ca269ba3b4d0fef3bc89366d7463..0e3c2c8a354779d34ed36042208935d12b55f40b 100644 (file)
@@ -63,7 +63,7 @@ __memchr (void const *s, int c_in, size_t n)
      performance.  On 64-bit hardware, unsigned long is generally 64
      bits already.  Change this typedef to experiment with
      performance.  */
-  typedef unsigned long int longword;
+  typedef unsigned long int longword _GL_ATTRIBUTE_MAY_ALIAS;
 
   unsigned reg_char c = (unsigned char) c_in;
 
index 128144d7f310f21c3cb018f5501df7e7cacf5c0f..610f9165a06eb232b0889b77f1c335708e0bb2ba 100644 (file)
@@ -40,7 +40,7 @@ memchr2 (void const *s, int c1_in, int c2_in, size_t n)
      performance.  On 64-bit hardware, unsigned long is generally 64
      bits already.  Change this typedef to experiment with
      performance.  */
-  typedef unsigned long int longword;
+  typedef unsigned long int longword _GL_ATTRIBUTE_MAY_ALIAS;
 
   unsigned char c1 = (unsigned char) c1_in;
   unsigned char c2 = (unsigned char) c2_in;
index a7683c9aea1f05c2c8fe5bf94f2b216c0c8c6f46..b859288d6893a8fa2bbfe66853915c28dbf9319e 100644 (file)
@@ -50,7 +50,7 @@ __memrchr (void const *s, int c_in, size_t n)
      performance.  On 64-bit hardware, unsigned long is generally 64
      bits already.  Change this typedef to experiment with
      performance.  */
-  typedef unsigned long int longword;
+  typedef unsigned long int longword _GL_ATTRIBUTE_MAY_ALIAS;
 
   unsigned reg_char c = (unsigned char) c_in;
 
index 9714698fcce7e41974671a6d2f72d937170125ac..4eaada4774e61b24a2da37a39c539ad11994249c 100644 (file)
@@ -42,7 +42,7 @@ rawmemchr (const void *s, int c_in)
 # else
 
   /* You can change this typedef to experiment with performance.  */
-  typedef uintptr_t longword;
+  typedef uintptr_t longword _GL_ATTRIBUTE_MAY_ALIAS;
   /* Verify that the longword type lacks padding bits.  */
   static_assert (UINTPTR_WIDTH == UCHAR_WIDTH * sizeof (uintptr_t));
 
index c3bfebce28c81425265012bce948bf5eb636a5f7..2e813bf580b137a40a6311e8cf9ec879198ffd5c 100644 (file)
@@ -28,7 +28,7 @@ strchrnul (const char *s, int c_in)
      performance.  On 64-bit hardware, unsigned long is generally 64
      bits already.  Change this typedef to experiment with
      performance.  */
-  typedef unsigned long int longword;
+  typedef unsigned long int longword _GL_ATTRIBUTE_MAY_ALIAS;
 
   unsigned char c = (unsigned char) c_in;
   if (!c)