qemu-arm
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/5] arm/digic: fix format-truncation warning


From: Peter Maydell
Subject: Re: [PATCH 2/5] arm/digic: fix format-truncation warning
Date: Mon, 28 Mar 2022 09:12:09 +0000

On Mon, 28 Mar 2022 at 09:47, <marcandre.lureau@redhat.com> wrote:
>
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> ../hw/arm/digic.c: In function ‘digic_init’:
> ../hw/arm/digic.c:45:54: error: ‘%d’ directive output may be truncated 
> writing between 1 and 11 bytes into a region of size 5 
> [-Werror=format-truncation=]
>    45 |         snprintf(name, DIGIC_TIMER_NAME_MLEN, "timer[%d]", i);
>       |                                                      ^~
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  hw/arm/digic.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/hw/arm/digic.c b/hw/arm/digic.c
> index 614232165cdc..6df554797734 100644
> --- a/hw/arm/digic.c
> +++ b/hw/arm/digic.c
> @@ -39,10 +39,7 @@ static void digic_init(Object *obj)
>      object_initialize_child(obj, "cpu", &s->cpu, 
> ARM_CPU_TYPE_NAME("arm946"));
>
>      for (i = 0; i < DIGIC4_NB_TIMERS; i++) {
> -#define DIGIC_TIMER_NAME_MLEN    11
> -        char name[DIGIC_TIMER_NAME_MLEN];
> -
> -        snprintf(name, DIGIC_TIMER_NAME_MLEN, "timer[%d]", i);
> +        g_autofree char *name = g_strdup_printf("timer[%d]", i);
>          object_initialize_child(obj, name, &s->timer[i], TYPE_DIGIC_TIMER);
>      }

This is a clear compiler false positive, given that DIGIC4_NB_TIMERS is 3.
But this is a nicer way to write the code than the static array anyway.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM



reply via email to

[Prev in Thread] Current Thread [Next in Thread]