# HG changeset patch # User William Astle # Date 1457071176 25200 # Node ID 7f538053492ca6226b0006082a302f62f3cbe9e6 # Parent c8ae69cdb5a9b3dfb5fbcb55a1d8eaa3462e6d40 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. diff -r c8ae69cdb5a9 -r 7f538053492c lwasm/output.c --- 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 outputl; outidx++) - { - linelength = write_code_BASIC_fprintf(of, linelength, &linenumber, cl -> output[outidx]); + for (outidx=0; outidx outputl; outidx++) + { + linelength = write_code_BASIC_fprintf(of, linelength, &linenumber, cl -> output[outidx]); + } } }