From: Paul Eggert Date: Sun, 26 Jul 2026 18:49:42 +0000 (-0700) Subject: Fix strict aliasing violations in memchr etc X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=936d5942f32abc29aebdf1ae36bf49fd19562bee;p=thirdparty%2Fgnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 8fb1fccc2c..e74699ea91 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2026-07-26 Paul Eggert + 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 diff --git a/lib/memchr.c b/lib/memchr.c index 6adac7e179..0e3c2c8a35 100644 --- a/lib/memchr.c +++ b/lib/memchr.c @@ -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; diff --git a/lib/memchr2.c b/lib/memchr2.c index 128144d7f3..610f9165a0 100644 --- a/lib/memchr2.c +++ b/lib/memchr2.c @@ -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; diff --git a/lib/memrchr.c b/lib/memrchr.c index a7683c9aea..b859288d68 100644 --- a/lib/memrchr.c +++ b/lib/memrchr.c @@ -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; diff --git a/lib/rawmemchr.c b/lib/rawmemchr.c index 9714698fcc..4eaada4774 100644 --- a/lib/rawmemchr.c +++ b/lib/rawmemchr.c @@ -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)); diff --git a/lib/strchrnul.c b/lib/strchrnul.c index c3bfebce28..2e813bf580 100644 --- a/lib/strchrnul.c +++ b/lib/strchrnul.c @@ -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)