From a0c833e9701d2ded1d38e7b79dde1566026c6191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Wed, 16 Dec 2020 20:26:34 +0100 Subject: [PATCH] voodoo: convert variable length arrays to malloc'd --- src/video/vid_voodoo_banshee.c | 29 ++++++++++++++++++++--------- src/video/vid_voodoo_display.c | 12 +++++++++--- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/video/vid_voodoo_banshee.c b/src/video/vid_voodoo_banshee.c index 2d3a378d5..7401df0d0 100644 --- a/src/video/vid_voodoo_banshee.c +++ b/src/video/vid_voodoo_banshee.c @@ -2083,8 +2083,8 @@ static void banshee_overlay_draw(svga_t *svga, int displine) case VIDPROCCFG_FILTER_MODE_DITHER_4X4: if (banshee->voodoo->scrfilter && banshee->voodoo->scrfilterEnabled) { - uint8_t fil[(svga->overlay_latch.xsize) * 3]; - uint8_t fil3[(svga->overlay_latch.xsize) * 3]; + uint8_t *fil = malloc((svga->overlay_latch.xsize) * 3); + uint8_t *fil3 = malloc((svga->overlay_latch.xsize) * 3); if (banshee->vidProcCfg & VIDPROCCFG_H_SCALE_ENABLE) /* leilei HACK - don't know of real 4x1 hscaled behavior yet, double for now */ { @@ -2146,6 +2146,9 @@ static void banshee_overlay_draw(svga_t *svga, int displine) fil[(x)*3+2] = vb_filter_v1_rb [fil[x*3+2]] [fil3[(x+1) *3+2]]; p[x] = (fil[x*3+2] << 16) | (fil[x*3+1] << 8) | fil[x*3]; } + + free(fil); + free(fil3); } else /* filter disabled by emulator option */ { @@ -2168,14 +2171,14 @@ static void banshee_overlay_draw(svga_t *svga, int displine) case VIDPROCCFG_FILTER_MODE_DITHER_2X2: if (banshee->voodoo->scrfilter && banshee->voodoo->scrfilterEnabled) { - uint8_t fil[(svga->overlay_latch.xsize) * 3]; - uint8_t soak[(svga->overlay_latch.xsize) * 3]; - uint8_t soak2[(svga->overlay_latch.xsize) * 3]; + uint8_t *fil = malloc((svga->overlay_latch.xsize) * 3); + uint8_t *soak = malloc((svga->overlay_latch.xsize) * 3); + uint8_t *soak2 = malloc((svga->overlay_latch.xsize) * 3); - uint8_t samp1[(svga->overlay_latch.xsize) * 3]; - uint8_t samp2[(svga->overlay_latch.xsize) * 3]; - uint8_t samp3[(svga->overlay_latch.xsize) * 3]; - uint8_t samp4[(svga->overlay_latch.xsize) * 3]; + uint8_t *samp1 = malloc((svga->overlay_latch.xsize) * 3); + uint8_t *samp2 = malloc((svga->overlay_latch.xsize) * 3); + uint8_t *samp3 = malloc((svga->overlay_latch.xsize) * 3); + uint8_t *samp4 = malloc((svga->overlay_latch.xsize) * 3); src = &svga->vram[src_addr2 & svga->vram_mask]; OVERLAY_SAMPLE(banshee->overlay_buffer[1]); @@ -2229,6 +2232,14 @@ static void banshee_overlay_draw(svga_t *svga, int displine) p[x] = (fil[x*3+2] << 16) | (fil[x*3+1] << 8) | fil[x*3]; } } + + free(fil); + free(soak); + free(soak2); + free(samp1); + free(samp2); + free(samp3); + free(samp4); } else /* filter disabled by emulator option */ { diff --git a/src/video/vid_voodoo_display.c b/src/video/vid_voodoo_display.c index 3a7df1ab3..5d3ad6e81 100644 --- a/src/video/vid_voodoo_display.c +++ b/src/video/vid_voodoo_display.c @@ -368,7 +368,7 @@ static void voodoo_filterline_v1(voodoo_t *voodoo, uint8_t *fil, int column, uin int x; // Scratchpad for avoiding feedback streaks - uint8_t fil3[(voodoo->h_disp) * 3]; + uint8_t *fil3 = malloc((voodoo->h_disp) * 3); /* 16 to 32-bit */ for (x=0; xthefilterg[fil3[x*3+1]][fil3[ (x+1) *3+1]]; fil[(x)*3+2] = voodoo->thefilter[fil3[x*3+2]][fil3[ (x+1) *3+2]]; } + + free(fil3); } @@ -434,7 +436,7 @@ static void voodoo_filterline_v2(voodoo_t *voodoo, uint8_t *fil, int column, uin int x; // Scratchpad for blending filter - uint8_t fil3[(voodoo->h_disp) * 3]; + uint8_t *fil3 = malloc((voodoo->h_disp) * 3); /* 16 to 32-bit */ for (x=0; xthefilterb [fil[(column-1)*3]][((src[column] & 31) << 3)]; fil3[(column-1)*3+1] = voodoo->thefilterg [fil[(column-1)*3+1]][(((src[column] >> 5) & 63) << 2)]; fil3[(column-1)*3+2] = voodoo->thefilter [fil[(column-1)*3+2]][(((src[column] >> 11) & 31) << 3)]; + + free(fil3); } void voodoo_callback(void *p) @@ -545,7 +549,7 @@ void voodoo_callback(void *p) if (voodoo->scrfilter && voodoo->scrfilterEnabled) { - uint8_t fil[(voodoo->h_disp) * 3]; /* interleaved 24-bit RGB */ + uint8_t *fil = malloc((voodoo->h_disp) * 3); /* interleaved 24-bit RGB */ if (voodoo->type == VOODOO_2) voodoo_filterline_v2(voodoo, fil, voodoo->h_disp, src, voodoo->line); @@ -556,6 +560,8 @@ void voodoo_callback(void *p) { p[x] = (voodoo->clutData256[fil[x*3]].b << 0 | voodoo->clutData256[fil[x*3+1]].g << 8 | voodoo->clutData256[fil[x*3+2]].r << 16); } + + free(fil); } else {