# HG changeset patch # User lost # Date 1231136081 0 # Node ID cef25b0088e68f02f88007934ec32cdc34b08442 # Parent d5fe306f1ab16b8d71caa7075821a0c876d5e705 Fixed some problems detected by valgrind and testing diff -r d5fe306f1ab1 -r cef25b0088e6 src/macro.c --- a/src/macro.c Mon Jan 05 05:40:33 2009 +0000 +++ b/src/macro.c Mon Jan 05 06:14:41 2009 +0000 @@ -110,7 +110,7 @@ if (as -> passnum == 2) return 1; - as -> macros -> lines = lwasm_realloc(as -> macros -> lines, sizeof(char *) * as -> macros -> numlines + 1); + as -> macros -> lines = lwasm_realloc(as -> macros -> lines, sizeof(char *) * (as -> macros -> numlines + 1)); as -> macros -> lines[as -> macros -> numlines] = lwasm_strdup(optr); as -> macros -> numlines += 1; return 1; @@ -187,7 +187,7 @@ } // have arg here - args = lwasm_realloc(args, nargs + 1); + args = lwasm_realloc(args, sizeof(char *) * (nargs + 1)); args[nargs] = lwasm_alloc(p2 - *p + 1); args[nargs][p2 - *p] = '\0'; memcpy(args[nargs], *p, p2 - *p); @@ -205,6 +205,8 @@ *p3 = '\0'; nargs++; + if (**p == ',') + (*p)++; } } @@ -225,7 +227,6 @@ for (lc = 0; lc < m -> numlines; lc++) { nl = lwasm_alloc(sizeof(lwasm_line_t)); - nl -> text = lwasm_strdup(linebuff); nl -> lineno = lc + 1; nl -> filename = m -> name; nl -> next = NULL; diff -r d5fe306f1ab1 -r cef25b0088e6 src/parse.c --- a/src/parse.c Mon Jan 05 05:40:33 2009 +0000 +++ b/src/parse.c Mon Jan 05 06:14:41 2009 +0000 @@ -115,9 +115,10 @@ // the reason this check is here is to allow for "private" // operation codes like "*pragma" which will be ignored by // other assemblers + // also skip empty ops if (!(instab[opnum].opcode)) { - if (*opc == '*' || *opc == ';') + if (*opc == '*' || *opc == ';' || !*opc) goto done_line; } @@ -142,17 +143,6 @@ if (as -> skipcond && instab[opnum].iscond == 0) goto done_line; - // register symbol if the operation won't - if (sym && instab[opnum].setsym == 0) - { - if (as -> passnum == 1) - { - debug_message(1, "Registering symbol '%s' at %04X", sym, as -> addr); - if (lwasm_register_symbol(as, l, sym, as -> addr, SYMBOL_NORM) < 0) - l -> sym = NULL; - } - } - // we've registered the symbol as needed // now we need to check for a macro call IFF we don't collide with // an operation code; otherwise, call the operation function @@ -180,6 +170,22 @@ } done_line: + if (!(as -> skipcond || as -> inmacro)) + { + // register symbol if the operation didn't + if (sym && instab[opnum].setsym == 0) + { + if (as -> passnum == 1) + { + debug_message(1, "Registering symbol '%s' at %04X", sym, as -> addr); + if (lwasm_register_symbol(as, l, sym, as -> addr, SYMBOL_NORM) < 0) + l -> sym = NULL; + else + l -> addrset = 1; + } + } + } + lwasm_free(opc); if (sym) lwasm_free(sym);