From cd93ea95079c4c5cd67b7a5ce1953b5bfa23646f Mon Sep 17 00:00:00 2001 From: Patryk Obara Date: Wed, 26 Feb 2020 12:53:30 +0100 Subject: [PATCH] Silence buffer overrun Coverity warning This buffer overrun could happen if implementer forgets to fill pointer svga.set_clock, but calls VGA_SetClock with index out of bounds. Placing assert in here should clear out false positives detected by Coverity. --- src/hardware/vga.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/hardware/vga.cpp b/src/hardware/vga.cpp index 386faeed..07c758ad 100644 --- a/src/hardware/vga.cpp +++ b/src/hardware/vga.cpp @@ -128,11 +128,13 @@ void VGA_SetClock(Bitu which,Bitu target) { best.n = n; } } - } + } /* Program the s3 clock chip */ - vga.s3.clk[which].m=best.m; - vga.s3.clk[which].r=r; - vga.s3.clk[which].n=best.n; + constexpr size_t vga_s3_clk_len = sizeof(vga.s3.clk) / sizeof(*vga.s3.clk); + assert(which < vga_s3_clk_len); + vga.s3.clk[which].m = best.m; + vga.s3.clk[which].r = r; + vga.s3.clk[which].n = best.n; VGA_StartResize(); }