qemu-devel
[Top][All Lists]
Advanced

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

Re: [PATCH 06/12] mc146818rtc: rtc_set_time(): initialize tm to zeroes


From: Peter Maydell
Subject: Re: [PATCH 06/12] mc146818rtc: rtc_set_time(): initialize tm to zeroes
Date: Tue, 26 Sep 2023 11:56:04 +0100

On Mon, 25 Sept 2023 at 20:42, Vladimir Sementsov-Ogievskiy
<vsementsov@yandex-team.ru> wrote:
>
> set_time() function doesn't set all the fields, so it's better to
> initialize tm structure. And Coverity will be happier about it.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> ---
>  hw/rtc/mc146818rtc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/rtc/mc146818rtc.c b/hw/rtc/mc146818rtc.c
> index c27c362db9..b63e1aeaea 100644
> --- a/hw/rtc/mc146818rtc.c
> +++ b/hw/rtc/mc146818rtc.c
> @@ -599,7 +599,7 @@ static void rtc_get_time(MC146818RtcState *s, struct tm 
> *tm)
>
>  static void rtc_set_time(MC146818RtcState *s)
>  {
> -    struct tm tm;
> +    struct tm tm = {0};
>      g_autofree const char *qom_path = object_get_canonical_path(OBJECT(s));
>
>      rtc_get_time(s, &tm);

This is probably a false positive, but initializing the struct is
easier to reason about for humans too.

Our "zero initialize a struct" syntax is "= {}" without the 0, though.
(The version with the 0 is the standards-blessed one, but in practice
some compiler versions have not been happy with it in all situations
and produce spurious warnings.)

thanks
-- PMM



reply via email to

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