changeset 410:7f538053492c

Fix a possible uninitialized variable reference Prevent the "basic" target from attempting to write data values for a code chunk that happens to end up being zero length. It's not clear that this could happen but robustness says to guard against it.
author William Astle <lost@l-w.ca>
date Thu, 03 Mar 2016 22:59:36 -0700
parents c8ae69cdb5a9
children 9f796134d6f4
files lwasm/output.c
diffstat 1 files changed, 12 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/lwasm/output.c	Thu Mar 03 22:33:40 2016 -0700
+++ b/lwasm/output.c	Thu Mar 03 22:59:36 2016 -0700
@@ -186,17 +186,20 @@
 			}
 		}
 	
-		linelength = write_code_BASIC_fprintf(of, linelength, &linenumber, startaddress);
-		linelength = write_code_BASIC_fprintf(of, linelength, &linenumber, lastaddress);
-	
-		for (cl = startblock; cl != endblock; cl = cl -> next)
+		if (startaddress != -1)
 		{
-			if (cl -> outputl < 0)
-				continue;
+			linelength = write_code_BASIC_fprintf(of, linelength, &linenumber, startaddress);
+			linelength = write_code_BASIC_fprintf(of, linelength, &linenumber, lastaddress);
+	
+			for (cl = startblock; cl != endblock; cl = cl -> next)
+			{
+				if (cl -> outputl < 0)
+					continue;
 		
-			for (outidx=0; outidx<cl -> outputl; outidx++)
-			{
-				linelength = write_code_BASIC_fprintf(of, linelength, &linenumber, cl -> output[outidx]);
+				for (outidx=0; outidx<cl -> outputl; outidx++)
+				{
+					linelength = write_code_BASIC_fprintf(of, linelength, &linenumber, cl -> output[outidx]);
+				}
 			}
 		}