qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Vivier <laurent@vivier.eu>
To: "Cédric Le Goater" <clg@redhat.com>
Cc: qemu-devel@nongnu.org,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Markus Armbruster" <armbru@redhat.com>
Subject: Re: [PATCH] log: Fix result of strstr to 'const char *'
Date: Tue, 9 Dec 2025 16:10:33 +0100	[thread overview]
Message-ID: <e8b4738b-cc55-4441-a72a-3f022f5b96ef@vivier.eu> (raw)
In-Reply-To: <20251209150346.650473-1-clg@redhat.com>

On 12/9/25 16:03, Cédric Le Goater 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 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 <clg@redhat.com>
> ---
>  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: Laurent Vivier <laurent@vivier.eu>


      parent reply	other threads:[~2025-12-09 15:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-09 15:03 [PATCH] log: Fix result of strstr to 'const char *' Cédric Le Goater
2025-12-09 15:07 ` Peter Maydell
2025-12-09 15:14   ` Cédric Le Goater
2025-12-09 15:21   ` Daniel P. Berrangé
2025-12-09 15:22     ` Cédric Le Goater
2025-12-09 15:10 ` Laurent Vivier [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e8b4738b-cc55-4441-a72a-3f022f5b96ef@vivier.eu \
    --to=laurent@vivier.eu \
    --cc=armbru@redhat.com \
    --cc=clg@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).