[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
- Re: [PATCH 01/12] hw/core/loader: load_at(): check size, (continued)
[PATCH 03/12] util/filemonitor-inotify: qemu_file_monitor_watch(): avoid overflow, Vladimir Sementsov-Ogievskiy, 2023/09/25
[PATCH 05/12] device_tree: qmp_dumpdtb(): stronger assertion, Vladimir Sementsov-Ogievskiy, 2023/09/25
[PATCH 06/12] mc146818rtc: rtc_set_time(): initialize tm to zeroes, Vladimir Sementsov-Ogievskiy, 2023/09/25
- Re: [PATCH 06/12] mc146818rtc: rtc_set_time(): initialize tm to zeroes,
Peter Maydell <=
[PATCH 08/12] block/nvme: nvme_process_completion() fix bound for cid, Vladimir Sementsov-Ogievskiy, 2023/09/25
[PATCH 07/12] pcie_sriov: unregister_vfs(): fix error path, Vladimir Sementsov-Ogievskiy, 2023/09/25
[PATCH 10/12] hw/core/loader: gunzip(): initialize z_stream, Vladimir Sementsov-Ogievskiy, 2023/09/25
[PATCH 11/12] hw/core/loader: read_targphys(): add upper bound, Vladimir Sementsov-Ogievskiy, 2023/09/25