Browse code

(uxnasm) Raise error when memory is overwritten.

Andrew Alderwick authored on 19/02/2022 00:27:28
Showing 1 changed files
... ...
@@ -193,6 +193,10 @@ writebyte(Uint8 b)
193 193
 		fprintf(stderr, "-- Writing in zero-page: %02x\n", b);
194 194
 		return 0;
195 195
 	}
196
+	else if(p.ptr < p.length) {
197
+		fprintf(stderr, "-- Memory overwrite: %04x -> %04x\n", p.length, p.ptr);
198
+		return 0;
199
+	}
196 200
 	p.data[p.ptr++] = b;
197 201
 	p.length = p.ptr;
198 202
 	litlast = 0;
... ...
@@ -213,6 +217,7 @@ writelitbyte(Uint8 b)
213 217
 	if(litlast) { /* combine literals */
214 218
 		Uint8 hb = p.data[p.ptr - 1];
215 219
 		p.ptr -= 2;
220
+		p.length = p.ptr;
216 221
 		return writeshort((hb << 8) + b, 1);
217 222
 	}
218 223
 	if(!writebyte(findopcode("LIT"))) return 0;