comparison lwasm/output.c @ 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 4411a6123716
children 9f0448022f1f
comparison
equal deleted inserted replaced
409:c8ae69cdb5a9 410:7f538053492c
184 184
185 lastaddress += cl -> outputl; 185 lastaddress += cl -> outputl;
186 } 186 }
187 } 187 }
188 188
189 linelength = write_code_BASIC_fprintf(of, linelength, &linenumber, startaddress); 189 if (startaddress != -1)
190 linelength = write_code_BASIC_fprintf(of, linelength, &linenumber, lastaddress); 190 {
191 191 linelength = write_code_BASIC_fprintf(of, linelength, &linenumber, startaddress);
192 for (cl = startblock; cl != endblock; cl = cl -> next) 192 linelength = write_code_BASIC_fprintf(of, linelength, &linenumber, lastaddress);
193 { 193
194 if (cl -> outputl < 0) 194 for (cl = startblock; cl != endblock; cl = cl -> next)
195 continue; 195 {
196 196 if (cl -> outputl < 0)
197 for (outidx=0; outidx<cl -> outputl; outidx++) 197 continue;
198 { 198
199 linelength = write_code_BASIC_fprintf(of, linelength, &linenumber, cl -> output[outidx]); 199 for (outidx=0; outidx<cl -> outputl; outidx++)
200 {
201 linelength = write_code_BASIC_fprintf(of, linelength, &linenumber, cl -> output[outidx]);
202 }
200 } 203 }
201 } 204 }
202 205
203 startblock = cl; 206 startblock = cl;
204 } 207 }