qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: "Richard Henderson" <richard.henderson@linaro.org>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	qemu-devel@nongnu.org
Cc: "Brad Smith" <brad@comstyle.com>,
	qemu-trivial@nongnu.org,
	"Daniel P . Berrangé" <berrange@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Michael Tokarev" <mjt@tls.msk.ru>
Subject: Re: [PATCH v2] ui/console-vc: Silence warning about sprintf() on OpenBSD
Date: Tue, 15 Oct 2024 17:03:30 +0200	[thread overview]
Message-ID: <4f8968d6-2608-4359-81e5-ff9233ef692f@redhat.com> (raw)
In-Reply-To: <3a7da33b-c802-44f2-8478-ce4de64665a4@linaro.org>

On 15/10/2024 16.47, Richard Henderson wrote:
> On 10/15/24 04:25, Thomas Huth wrote:
>> The linker on OpenBSD complains:
>>
>>   ld: warning: console-vc.c:824 (../src/ui/console-vc.c:824)([...]):
>>   warning: sprintf() is often misused, please use snprintf()
>>
>> Using g_strdup_printf() is certainly better here, so let's switch
>> to that function instead.
>>
>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>> ---
>>   v2: Use g_strdup_printf() instead of snprintf()
>>
>>   ui/console-vc.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/ui/console-vc.c b/ui/console-vc.c
>> index 8393d532e7..53fcee88f4 100644
>> --- a/ui/console-vc.c
>> +++ b/ui/console-vc.c
>> @@ -648,7 +648,7 @@ static void vc_putchar(VCChardev *vc, int ch)
>>       QemuTextConsole *s = vc->console;
>>       int i;
>>       int x, y;
>> -    char response[40];
>> +    g_autofree char *response = NULL;
>>       switch(vc->state) {
>>       case TTY_STATE_NORM:
>> @@ -821,7 +821,7 @@ static void vc_putchar(VCChardev *vc, int ch)
>>                       break;
>>                   case 6:
>>                       /* report cursor position */
>> -                    sprintf(response, "\033[%d;%dR",
>> +                    response = g_strdup_printf("\033[%d;%dR",
>>                              (s->y_base + s->y) % s->total_height + 1,
>>                               s->x + 1);
>>                       vc_respond_str(vc, response);
> 
> Could be better by limiting the scope of the variable to this case.

I tried that first, but then I need curly braces around the whole case block 
to avoid compiler warnings, which is ugly, too, so I decided to keep it at 
the top.

  Thomas



  reply	other threads:[~2024-10-15 15:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-15 11:25 [PATCH v2] ui/console-vc: Silence warning about sprintf() on OpenBSD Thomas Huth
2024-10-15 11:30 ` Marc-André Lureau
2024-10-15 13:00 ` Alex Bennée
2024-10-15 14:47 ` Richard Henderson
2024-10-15 15:03   ` Thomas Huth [this message]
2024-10-18 16:20 ` Michael Tokarev

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=4f8968d6-2608-4359-81e5-ff9233ef692f@redhat.com \
    --to=thuth@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=berrange@redhat.com \
    --cc=brad@comstyle.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mjt@tls.msk.ru \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@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).