From 81f0364ab28cd95b2d4f79c45055b2536002401f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl-Henrik=20Sk=C3=A5rstedt?= Date: Sat, 12 Dec 2015 13:22:23 -0800 Subject: [PATCH] Disassembler local label improvement - Determination for negative branches to local labels were one off which meant lots of unnecessary local labels at end of long functions - struse null/0-length check was reverse causing access to 0 --- disassembler/x65dsasm.cpp | 22 +++++++++++----------- struse.h | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/disassembler/x65dsasm.cpp b/disassembler/x65dsasm.cpp index 5663b6b..ae97a21 100644 --- a/disassembler/x65dsasm.cpp +++ b/disassembler/x65dsasm.cpp @@ -1786,10 +1786,10 @@ void GetReferences(unsigned char *mem, size_t bytes, bool acc_16, bool ind_16, i } else { // forward check while (j!=refs.end()) { ++j; - if (j!=refs.end() && !j->local) - skip_global = true; if (j==refs.end() || trg_addraddress) break; + if (j!=refs.end() && !j->local) + skip_global = true; } } if (skip_global) { @@ -1884,15 +1884,6 @@ bool IsReadOnlyInstruction(MNM_Base op_base) static const char spacing[] = " "; void Disassemble(strref filename, unsigned char *mem, size_t bytes, bool acc_16, bool ind_16, int addr, bool ill_wdc, const dismnm *opcodes, bool src, int init_data, strref labels) { - FILE *f = stdout; - bool opened = false; - if (filename) { - f = fopen(strown<512>(filename).c_str(), "w"); - if (!f) - return; - opened = true; - } - const char *spc = src ? "" : spacing; strref prev_src; @@ -1908,6 +1899,15 @@ void Disassemble(strref filename, unsigned char *mem, size_t bytes, bool acc_16, bool is_ptrs = is_data && (refs[0].data==DT_PTRS || refs[0].data==DT_PTRS_DATA); strown<256> out; + FILE *f = stdout; + bool opened = false; + if (filename) { + f = fopen(strown<512>(filename).c_str(), "w"); + if (!f) + return; + opened = true; + } + while (bytes) { // Determine if current address is referenced from somewhere while (curr_label_index<(int)refs.size() && addr >= refs[curr_label_index].address) { diff --git a/struse.h b/struse.h index 319ee30..ec1843b 100644 --- a/struse.h +++ b/struse.h @@ -1500,7 +1500,7 @@ unsigned int strref::ahextoui_skip() { const char *scan = string; strl_t left = length; - while (*scan<=0x20 && left) { + while (left && *scan<=0x20) { scan++; left--; }