On 12/9/25 16:21, Daniel P. Berrangé wrote:
On Tue, Dec 09, 2025 at 03:07:04PM +0000, Peter Maydell wrote:
On Tue, 9 Dec 2025 at 15:04, Cédric Le Goater <[email protected]> wrote:

Assigning the result of strstr() to a 'char *' is unsafe since
strstr() returns a pointer into the original string which is a
read-only 'const char *' string. Newer compilers

Which ones? Or does this depend on how the libc headers have
marked up the strstr() prototype?

I don't believe it is compiler related, rather this is an
ehancement in glibc 2.42.9000 / git master

   
https://sourceware.org/git/?p=glibc.git;a=commit;h=cd748a63ab1a7ae846175c532a3daab341c62690

AFAICT it should work with any gcc we have

Although the commit talks about C23, we get it regardless as we have
_GNU_SOURCE defined.

yes. glibc 2.42.9000 has :


+# if __GLIBC_USE (ISOC23) && defined __glibc_const_generic && !defined _LIBC
+#  define strstr(HAYSTACK, NEEDLE)                     \
+  __glibc_const_generic (HAYSTACK, const char *,       \
+                        strstr (HAYSTACK, NEEDLE))
+# endif


C.


Reply via email to