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

2023-09-26 Thread Peter Maydell
On Mon, 25 Sept 2023 at 20:42, Vladimir Sementsov-Ogievskiy
 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 
> ---
>  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, );

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



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

2023-09-25 Thread Vladimir Sementsov-Ogievskiy
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 
---
 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, );
-- 
2.34.1