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? > now complain when the > result of strstr() is not a 'const char *' : > > ../util/log.c:208:24: error: initialization discards ‘const’ qualifier from > pointer target type [-Werror=discarded-qualifiers] > 208 | char *pidstr = strstr(filename, "%"); > | ^~~~~~ > > Fix that. > > Signed-off-by: Cédric Le Goater <[email protected]> > --- > util/log.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/util/log.c b/util/log.c > index > 41f78ce86b2522b8b7072c8b76d8e18603142db6..c44d66b5ce78338cf1b2cd26b7503cb94d4570cb > 100644 > --- a/util/log.c > +++ b/util/log.c > @@ -203,7 +203,7 @@ static ValidFilenameTemplateResult > valid_filename_template(const char *filename, bool per_thread, Error **errp) > { > if (filename) { > - char *pidstr = strstr(filename, "%"); > + const char *pidstr = strstr(filename, "%"); > > if (pidstr) { > /* We only accept one %d, no other format strings */ > -- Reviewed-by: Peter Maydell <[email protected]> thanks -- PMM
