From 3006fa8d26fe8b8d9b344c9e983513cd59477cb7 Mon Sep 17 00:00:00 2001 From: Bernhard Beschow Date: Sun, 19 Oct 2025 23:02:57 +0200 Subject: [PATCH] hw/rtc/mc146818rtc: Use ARRAY_SIZE macro MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Avoids the error-prone repetition of the array size. Signed-off-by: Bernhard Beschow Reviewed-by: Philippe Mathieu-Daudé Message-ID: <20251019210303.104718-5-shentey@gmail.com> Signed-off-by: Philippe Mathieu-Daudé --- hw/rtc/mc146818rtc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/rtc/mc146818rtc.c b/hw/rtc/mc146818rtc.c index 61e9c0bf99..5a89062b4c 100644 --- a/hw/rtc/mc146818rtc.c +++ b/hw/rtc/mc146818rtc.c @@ -726,13 +726,14 @@ static uint64_t cmos_ioport_read(void *opaque, hwaddr addr, void mc146818rtc_set_cmos_data(MC146818RtcState *s, int addr, int val) { - if (addr >= 0 && addr <= 127) + if (addr >= 0 && addr < ARRAY_SIZE(s->cmos_data)) { s->cmos_data[addr] = val; + } } int mc146818rtc_get_cmos_data(MC146818RtcState *s, int addr) { - assert(addr >= 0 && addr <= 127); + assert(addr >= 0 && addr < ARRAY_SIZE(s->cmos_data)); return s->cmos_data[addr]; } -- 2.47.3