diff lwasm/list.c @ 273:1409debcb1a0

Fix crash on listing when nested noexpand macros are used Macros flagged noexpand were causing a segfault during listing. The problem was incorrect accounting for nesting levels for noexpand macros causing the listing handler to fall off the end of the program in certain circumstances and in other circumstances it would fail to suppress expansion. Both the segfault in the case of misbehaviour and the misbhaviour itself are corrected with this update. If you do not use nested noexpand macros, this bug has no effect.
author William Astle <lost@l-w.ca>
date Sat, 25 May 2013 13:35:46 -0600
parents e09985968e64
children dc763f806dc4
line wrap: on
line diff
--- a/lwasm/list.c	Sat Apr 20 11:00:11 2013 -0600
+++ b/lwasm/list.c	Sat May 25 13:35:46 2013 -0600
@@ -75,12 +75,12 @@
 		{
 			obytelen = 0;
 			int nc = 0;
-			for (nl = cl; ; nl = nl -> next)
+			for (nl = cl; nl; nl = nl -> next)
 			{
 				if (nl -> noexpand_start)
-					nc++;
+					nc += nl -> noexpand_start;
 				if (nl -> noexpand_end)
-					nc--;
+					nc -= nl -> noexpand_end;
 				
 				if (nl -> outputl > 0)
 					obytelen += nl -> outputl;
@@ -107,7 +107,8 @@
 				if (nc >= obytelen)
 					break;
 			}
-			nl = nl -> next;
+			if (nl)
+				nl = nl -> next;
 		}
 		else
 		{