]> git.proxmox.com Git - mirror_qemu.git/commitdiff
hw/fmopl: Fix buffer access out-of-bounds errors
authorStefan Weil <weil@mail.berlios.de>
Sat, 12 Mar 2011 16:43:56 +0000 (17:43 +0100)
committerBlue Swirl <blauwirbel@gmail.com>
Sun, 13 Mar 2011 13:35:21 +0000 (13:35 +0000)
Index 75 is one too large for AR_TABLE[75], DR_TABLE[75].
This error was reported by cppcheck.

hw/fmopl.c:600: error: Buffer access out-of-bounds: OPL.AR_TABLE
hw/fmopl.c:601: error: Buffer access out-of-bounds: OPL.DR_TABLE

Fix this by limiting the access to the allowed range.
MultiArcadeMachineEmulator has newer versions of fmopl,
but using these requires more efforts.

Cc: Blue Swirl <blauwirbel@gmail.com>
Reviewed-by: malc <av1474@comtv.ru>
Signed-off-by: Stefan Weil <weil@mail.berlios.de>
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
hw/fmopl.c

index 3df1806a912001316f21059598e096988066cf38..d8a0f36b357a130ed22fd66f34f0cf9b58d234cd 100644 (file)
 #define PI 3.14159265358979323846
 #endif
 
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#endif
+
 /* -------------------- for debug --------------------- */
 /* #define OPL_OUTPUT_LOG */
 #ifdef OPL_OUTPUT_LOG
@@ -595,7 +599,7 @@ static void init_timetables( FM_OPL *OPL , int ARRATE , int DRRATE )
                OPL->AR_TABLE[i] = rate / ARRATE;
                OPL->DR_TABLE[i] = rate / DRRATE;
        }
-       for (i = 60;i < 76;i++)
+       for (i = 60; i < ARRAY_SIZE(OPL->AR_TABLE); i++)
        {
                OPL->AR_TABLE[i] = EG_AED-1;
                OPL->DR_TABLE[i] = OPL->DR_TABLE[60];