diff mbox series

[7/9] hw/riscv/virt: Replace sprintf() by snprintf()

Message ID 20240411104340.6617-8-philmd@linaro.org
State New
Headers show
Series misc: Replace sprintf() by snprintf() due to macOS deprecation | expand

Commit Message

Philippe Mathieu-Daudé April 11, 2024, 10:43 a.m. UTC
sprintf() is deprecated on Darwin since macOS 13.0 / XCode 14.1,
resulting in painful developper experience. Use snprintf() instead.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/riscv/virt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Richard Henderson April 11, 2024, 9:29 p.m. UTC | #1
On 4/11/24 03:43, Philippe Mathieu-Daudé wrote:
> sprintf() is deprecated on Darwin since macOS 13.0 / XCode 14.1,
> resulting in painful developper experience. Use snprintf() instead.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/riscv/virt.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
> index d171e74f7b..b3fede1207 100644
> --- a/hw/riscv/virt.c
> +++ b/hw/riscv/virt.c
> @@ -1619,7 +1619,7 @@ static char *virt_get_aia_guests(Object *obj, Error **errp)
>       RISCVVirtState *s = RISCV_VIRT_MACHINE(obj);
>       char val[32];
>   
> -    sprintf(val, "%d", s->aia_guests);
> +    snprintf(val, sizeof(val), "%d", s->aia_guests);
>       return g_strdup(val);
>   }

g_strdup_printf.

> @@ -1785,7 +1785,8 @@ static void virt_machine_class_init(ObjectClass *oc, void *data)
>       object_class_property_add_str(oc, "aia-guests",
>                                     virt_get_aia_guests,
>                                     virt_set_aia_guests);
> -    sprintf(str, "Set number of guest MMIO pages for AIA IMSIC. Valid value "
> +    snprintf(str, sizeof(str),
> +                 "Set number of guest MMIO pages for AIA IMSIC. Valid value "
>                    "should be between 0 and %d.", VIRT_IRQCHIP_MAX_GUESTS);
>       object_class_property_set_description(oc, "aia-guests", str);
>       object_class_property_add(oc, "acpi", "OnOffAuto",

Ok.


r~
diff mbox series

Patch

diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
index d171e74f7b..b3fede1207 100644
--- a/hw/riscv/virt.c
+++ b/hw/riscv/virt.c
@@ -1619,7 +1619,7 @@  static char *virt_get_aia_guests(Object *obj, Error **errp)
     RISCVVirtState *s = RISCV_VIRT_MACHINE(obj);
     char val[32];
 
-    sprintf(val, "%d", s->aia_guests);
+    snprintf(val, sizeof(val), "%d", s->aia_guests);
     return g_strdup(val);
 }
 
@@ -1785,7 +1785,8 @@  static void virt_machine_class_init(ObjectClass *oc, void *data)
     object_class_property_add_str(oc, "aia-guests",
                                   virt_get_aia_guests,
                                   virt_set_aia_guests);
-    sprintf(str, "Set number of guest MMIO pages for AIA IMSIC. Valid value "
+    snprintf(str, sizeof(str),
+                 "Set number of guest MMIO pages for AIA IMSIC. Valid value "
                  "should be between 0 and %d.", VIRT_IRQCHIP_MAX_GUESTS);
     object_class_property_set_description(oc, "aia-guests", str);
     object_class_property_add(oc, "acpi", "OnOffAuto",