From 8b84813c6ea4beb094c2a4c2a09da3e92a7eeb14 Mon Sep 17 00:00:00 2001 From: Andrew Alderwick Date: Sat, 19 Feb 2022 00:27:28 +0000 Subject: [PATCH] (uxnasm) Raise error when memory is overwritten. --- src/uxnasm.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/uxnasm.c b/src/uxnasm.c index 7e5adb9..63d0c18 100644 --- a/src/uxnasm.c +++ b/src/uxnasm.c @@ -193,6 +193,10 @@ writebyte(Uint8 b) fprintf(stderr, "-- Writing in zero-page: %02x\n", b); return 0; } + else if(p.ptr < p.length) { + fprintf(stderr, "-- Memory overwrite: %04x -> %04x\n", p.length, p.ptr); + return 0; + } p.data[p.ptr++] = b; p.length = p.ptr; litlast = 0; @@ -213,6 +217,7 @@ writelitbyte(Uint8 b) if(litlast) { /* combine literals */ Uint8 hb = p.data[p.ptr - 1]; p.ptr -= 2; + p.length = p.ptr; return writeshort((hb << 8) + b, 1); } if(!writebyte(findopcode("LIT"))) return 0;