From 922389fd6b61ec12d571a0bb1839d7415e693537 Mon Sep 17 00:00:00 2001 From: mzxrules Date: Tue, 3 Jun 2025 23:25:28 -0400 Subject: [PATCH] Document SysCfb_GetFbPtr bug --- src/code/graph.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/code/graph.c b/src/code/graph.c index 8a4646808f..63c2fdba91 100644 --- a/src/code/graph.c +++ b/src/code/graph.c @@ -141,6 +141,9 @@ void Graph_InitTHGA(GraphicsContext* gfxCtx) { gfxCtx->overlayBuffer = pool->overlayBuffer; gfxCtx->workBuffer = pool->workBuffer; + //! @bug fbIdx is a signed integer that can overflow into the negatives. When compiled with IDO, the remainder + //! operator will yield -1 for odd negative values of fbIdx (i.e. the same as C99 onwards). + //! This results in an out of bounds array access in SysCfb_GetFbPtr due to the negative index value. gfxCtx->curFrameBuffer = SysCfb_GetFbPtr(gfxCtx->fbIdx % 2); gfxCtx->unk_014 = 0; }