From c701b95541c50ad3798eeb865254ceecb88706ce Mon Sep 17 00:00:00 2001 From: Andrew Alderwick Date: Mon, 13 Mar 2023 06:04:33 +0000 Subject: [PATCH] Detect stack overflows with greater than 255 bytes. --- src/uxn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uxn.c b/src/uxn.c index ff6dbb1..c488914 100644 --- a/src/uxn.c +++ b/src/uxn.c @@ -28,7 +28,7 @@ WITH REGARD TO THIS SOFTWARE. */ #define HALT(c) { return uxn_halt(u, ins, (c), pc - 1); } -#define SET(mul, add) { if(mul > s->ptr) HALT(1) s->ptr += k * mul + add; if(s->ptr > 254) HALT(2) } +#define SET(mul, add) { if(mul > s->ptr) HALT(1) tmp = s->ptr + k * mul + add; if(tmp > 254) HALT(2) s->ptr = tmp; } #define PUT(o, v) { s->dat[s->ptr - 1 - (o)] = (v); } #define PUT2(o, v) { tmp = (v); s->dat[s->ptr - o - 2] = tmp >> 8; s->dat[s->ptr - o - 1] = tmp; } #define PUSH(stack, v) { if(s->ptr > 254) HALT(2) stack->dat[stack->ptr++] = (v); }