qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] ui/console-vc: Silence warning about sprintf() on OpenBSD
@ 2024-10-15 11:25 Thomas Huth
  2024-10-15 11:30 ` Marc-André Lureau
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Thomas Huth @ 2024-10-15 11:25 UTC (permalink / raw)
  To: Marc-André Lureau, qemu-devel
  Cc: Brad Smith, qemu-trivial, Daniel P . Berrangé,
	Alex Bennée, Michael Tokarev

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);
-- 
2.47.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] ui/console-vc: Silence warning about sprintf() on OpenBSD
  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
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Marc-André Lureau @ 2024-10-15 11:30 UTC (permalink / raw)
  To: Thomas Huth
  Cc: qemu-devel, Brad Smith, qemu-trivial, Daniel P . Berrangé,
	Alex Bennée, Michael Tokarev

On Tue, Oct 15, 2024 at 3:25 PM Thomas Huth <thuth@redhat.com> 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>

Reviewed-by: Marc-André Lureau <marcandre.lureau@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);
> --
> 2.47.0
>



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] ui/console-vc: Silence warning about sprintf() on OpenBSD
  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-18 16:20 ` Michael Tokarev
  3 siblings, 0 replies; 6+ messages in thread
From: Alex Bennée @ 2024-10-15 13:00 UTC (permalink / raw)
  To: Thomas Huth
  Cc: Marc-André Lureau, qemu-devel, Brad Smith, qemu-trivial,
	Daniel P . Berrangé, Michael Tokarev

Thomas Huth <thuth@redhat.com> writes:

> 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>

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] ui/console-vc: Silence warning about sprintf() on OpenBSD
  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
  2024-10-18 16:20 ` Michael Tokarev
  3 siblings, 1 reply; 6+ messages in thread
From: Richard Henderson @ 2024-10-15 14:47 UTC (permalink / raw)
  To: Thomas Huth, Marc-André Lureau, qemu-devel
  Cc: Brad Smith, qemu-trivial, Daniel P . Berrangé,
	Alex Bennée, Michael Tokarev

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.
But either way,

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] ui/console-vc: Silence warning about sprintf() on OpenBSD
  2024-10-15 14:47 ` Richard Henderson
@ 2024-10-15 15:03   ` Thomas Huth
  0 siblings, 0 replies; 6+ messages in thread
From: Thomas Huth @ 2024-10-15 15:03 UTC (permalink / raw)
  To: Richard Henderson, Marc-André Lureau, qemu-devel
  Cc: Brad Smith, qemu-trivial, Daniel P . Berrangé,
	Alex Bennée, Michael Tokarev

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



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] ui/console-vc: Silence warning about sprintf() on OpenBSD
  2024-10-15 11:25 [PATCH v2] ui/console-vc: Silence warning about sprintf() on OpenBSD Thomas Huth
                   ` (2 preceding siblings ...)
  2024-10-15 14:47 ` Richard Henderson
@ 2024-10-18 16:20 ` Michael Tokarev
  3 siblings, 0 replies; 6+ messages in thread
From: Michael Tokarev @ 2024-10-18 16:20 UTC (permalink / raw)
  To: Thomas Huth, Marc-André Lureau, qemu-devel
  Cc: Brad Smith, qemu-trivial, Daniel P . Berrangé,
	Alex Bennée

15.10.2024 14: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.

Reviewed-by: Michael Tokarev <mjt@tls.msk.ru>

Queued for qemu-trivial, thanks!

/mjt


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-10-18 16:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2024-10-18 16:20 ` Michael Tokarev

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).