uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit 81ab3a7a7417e4390d7e7a594f26303d6ba52071
parent a8df7ca410d7cba4702bda9c29be2421d5dab918
Author: Andrew Alderwick <andrew@alderwick.co.uk>
Date:   Mon, 20 Sep 2021 23:12:11 +0100

Fixed PPU out-of-bounds crash

Diffstat:
Msrc/devices/ppu.c | 8+++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/devices/ppu.c b/src/devices/ppu.c @@ -22,7 +22,7 @@ static Uint8 blending[5][16] = { static void ppu_clear(Ppu *p) { - int i; + unsigned int i; for(i = 0; i < p->stride * p->height; ++i) p->dat[i] = 0; } @@ -30,8 +30,10 @@ ppu_clear(Ppu *p) unsigned int ppu_pixel(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 color) { - unsigned int i = x / PPW + y * p->stride, shift = x % PPW * 4; - unsigned int ret = p->dat[i]; + unsigned int ret, i = x / PPW + y * p->stride, shift = x % PPW * 4; + if(x >= p->width || y >= p->height) + return 0; + ret = p->dat[i]; if(fg) shift += 2; p->dat[i] &= ~(3 << shift); p->dat[i] |= color << shift;