changeset 159:8967eb907324

Trap negative sizes for [rz]m[bdq] and flag error
author lost@l-w.ca
date Sun, 28 Aug 2011 14:16:45 -0600
parents 8dead67ba607
children 02804b7c051c
files lwasm/pseudo.c
diffstat 1 files changed, 40 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/lwasm/pseudo.c	Sun Aug 28 14:16:10 2011 -0600
+++ b/lwasm/pseudo.c	Sun Aug 28 14:16:45 2011 -0600
@@ -527,6 +527,13 @@
 	
 	if (lw_expr_istype(expr, lw_expr_type_int))
 	{
+		if (lw_expr_intval(expr) < 0)
+		{
+			lwasm_register_error(as, l, "Negative reservation sizes make no sense!");
+			l -> len = 0;
+			l -> dlen = 0;
+			return;
+		}
 		if (l -> inmod)
 			l -> dlen = lw_expr_intval(expr);
 		else
@@ -540,7 +547,7 @@
 		return;
 
 	if (l -> len < 0 || l -> dlen < 0)
-		lwasm_register_error(as, l, "Expression not constant");
+		lwasm_register_error(as, l, "Expression not constant: %d %d", l -> len, l -> dlen);
 }
 
 PARSEFUNC(pseudo_parse_rmd)
@@ -604,6 +611,13 @@
 	
 	if (lw_expr_istype(expr, lw_expr_type_int))
 	{
+		if (lw_expr_intval(expr) < 0)
+		{
+			lwasm_register_error(as, l, "Negative reservation sizes make no sense!");
+			l -> len = 0;
+			l -> dlen = 0;
+			return;
+		}
 		if (l -> inmod)
 			l -> dlen = lw_expr_intval(expr) * 2;
 		else
@@ -681,6 +695,13 @@
 	
 	if (lw_expr_istype(expr, lw_expr_type_int))
 	{
+		if (lw_expr_intval(expr) < 0)
+		{
+			lwasm_register_error(as, l, "Negative reservation sizes make no sense!");
+			l -> len = 0;
+			l -> dlen = 0;
+			return;
+		}
 		if (l -> inmod)
 			l -> dlen = lw_expr_intval(expr) * 4;
 		else 
@@ -722,6 +743,12 @@
 	
 	if (lw_expr_istype(expr, lw_expr_type_int))
 	{
+		if (lw_expr_intval(expr) < 0)
+		{
+			lwasm_register_error(as, l, "Negative block sizes make no sense!");
+			l -> len = 0;
+			return;
+		}
 		l -> len = lw_expr_intval(expr) * 4;
 	}
 }
@@ -765,6 +792,12 @@
 	
 	if (lw_expr_istype(expr, lw_expr_type_int))
 	{
+		if (lw_expr_intval(expr) < 0)
+		{
+			lwasm_register_error(as, l, "Negative block sizes make no sense!");
+			l -> len = 0;
+			return;
+		}
 		l -> len = lw_expr_intval(expr) * 2;
 	}
 }
@@ -807,6 +840,12 @@
 	
 	if (lw_expr_istype(expr, lw_expr_type_int))
 	{
+		if (lw_expr_intval(expr) < 0)
+		{
+			lwasm_register_error(as, l, "Negative block sizes make no sense!");
+			l -> len = 0;
+			return;
+		}
 		l -> len = lw_expr_intval(expr);
 	}
 }