changeset 283:210d261a614d

Make byte overflow detection for indexing work better There are *two* places where indexed addressing is calculated - lea style instructions and general addressing instructions. Actually check for byte overflows in both places. Also, extend byte overflow checking to all 8 bit offsets from index registers, not just PCR.
author William Astle <lost@l-w.ca>
date Mon, 02 Sep 2013 10:49:57 -0600
parents 3c421f24c9b8
children a1a88a8ddc98 e7fc269a4176
files lwasm/insn_gen.c lwasm/insn_indexed.c
diffstat 2 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/lwasm/insn_gen.c	Sat Aug 31 11:46:00 2013 -0600
+++ b/lwasm/insn_gen.c	Mon Sep 02 10:49:57 2013 -0600
@@ -270,7 +270,16 @@
 	{
 		lwasm_emit(l, l -> pb);
 		if (l -> lint > 0)
+		{
+			int i;
+			i = lw_expr_intval(e);
+			if (l -> lint == 1)
+			{
+				if (i < -128 || i > 127)
+					lwasm_register_error(as, l, "Byte overflow");
+			}
 			lwasm_emitexpr(l, e, l -> lint);
+		}
 		return;
 	}
 	
--- a/lwasm/insn_indexed.c	Sat Aug 31 11:46:00 2013 -0600
+++ b/lwasm/insn_indexed.c	Mon Sep 02 10:49:57 2013 -0600
@@ -581,7 +581,7 @@
 {
 	lw_expr_t e;
 	
-	if (l -> lint == 1 && (l -> pb == 0x9c || l -> pb == 0x8c))
+	if (l -> lint == 1)
 	{
 		int i;
 		e = lwasm_fetch_expr(l, 0);