Mercurial > hg > index.cgi
comparison lwasm/pass1.c @ 530:65c2085e0398
Don't rely on undefined memory before start of instab
When encountering a symbol on a line by itself, cl->insn was used to index
into the instab array. Unfortunately, in that case, cl->insn will be -1
which will refer to memory before the start of instab. Depending on the
compiler and linker, that could be anything.
This would only have a visible effect on the OS9 target which has separate
data and code address counters. On other targets, the two counters are kept
in sync.
This patch should short circuit that unfortunate code issue.
author | William Astle <lost@l-w.ca> |
---|---|
date | Wed, 09 Mar 2022 15:56:03 -0700 |
parents | 428039e88a0b |
children | 3f81d8b11e5b |
comparison
equal
deleted
inserted
replaced
529:428039e88a0b | 530:65c2085e0398 |
---|---|
428 if (cl -> sym && cl -> symset == 0) | 428 if (cl -> sym && cl -> symset == 0) |
429 { | 429 { |
430 debug_message(as, 50, "Register symbol %s: %s", cl -> sym, lw_expr_print(cl -> addr)); | 430 debug_message(as, 50, "Register symbol %s: %s", cl -> sym, lw_expr_print(cl -> addr)); |
431 | 431 |
432 // register symbol at line address | 432 // register symbol at line address |
433 if (instab[cl -> insn].flags & lwasm_insn_setdata) | 433 if ((cl -> insn >= 0) && (instab[cl -> insn].flags & lwasm_insn_setdata)) |
434 { | 434 { |
435 if (!register_symbol(as, cl, cl -> sym, cl -> daddr, symbol_flag_none)) | 435 if (!register_symbol(as, cl, cl -> sym, cl -> daddr, symbol_flag_none)) |
436 { | 436 { |
437 // symbol error | 437 // symbol error |
438 // lwasm_register_error2(as, cl, E_SYMBOL_BAD, "(%s)", cl -> sym); | 438 // lwasm_register_error2(as, cl, E_SYMBOL_BAD, "(%s)", cl -> sym); |