diff --git a/dis.h b/dis.h index c48a6c2..91dfcb9 100644 --- a/dis.h +++ b/dis.h @@ -20,6 +20,8 @@ */ +#include + extern bool sevenbit; /* if true, mask character data with 0x7f to ignore MSB */ @@ -124,10 +126,10 @@ char *get_name(addr_t loc); #define OFS 267 extern FILE *yyin, *yyout; -int lineno; +extern int lineno; int yywrap(), yyerror(); -char *emalloc(); +void *emalloc (size_t n); typedef union { int ival; diff --git a/lex.l b/lex.l index 3c637c6..e8bb8e2 100644 --- a/lex.l +++ b/lex.l @@ -23,15 +23,15 @@ %{ #undef ECHO #include +#include #include #include #include #include "dis.h" int lineno = 0; -char *strcpy(); %} -%option nounput +%option noinput nounput digit [0-9] hexdigit [0-9a-fA-F] @@ -75,7 +75,7 @@ alphanum [0-9a-zA-Z_] } {alpha}{alphanum}* { - token.sval = emalloc((unsigned) strlen(yytext)+1); + token.sval = emalloc(strlen(yytext)+1); (void)strcpy((char *)token.sval, (char *)yytext); return NAME; } @@ -90,13 +90,12 @@ alphanum [0-9a-zA-Z_] %% -char * -emalloc(n) -unsigned n; +void * +emalloc(size_t n) { - char *ptr; + void *ptr; - if ((ptr = malloc(n)) == (char *) 0) { + if ((ptr = malloc(n)) == NULL) { (void) fprintf(stderr,"out of core"); exit(1); } diff --git a/main.c b/main.c index a6f101d..d440162 100644 --- a/main.c +++ b/main.c @@ -90,7 +90,7 @@ void trace_inst (addr_t addr) { int opcode; register struct info *ip; - int operand; + int operand = 0; int istart; for (;;) @@ -116,7 +116,6 @@ void trace_inst (addr_t addr) switch(ip->nb) { case 1: - operand = 0; /* only to avoid "may be used unitialized" warning */ break; case 2: operand = getbyte(addr); @@ -232,7 +231,7 @@ void do_ptrace (void) { for (int i = 0; i 0; len--) f[i++] |= LOADED; @@ -544,6 +545,7 @@ void loadfile (void) i = getword(RUNLOC); start_trace(i, "**RUN**"); } + fclose(fp); return; } @@ -608,6 +610,8 @@ void c64loadfile (void) f[i++] |= LOADED; } + fclose(fp); + start_trace(base_addr, "**C64BIN**"); } @@ -637,6 +641,8 @@ void binaryloadfile (void) f [i++] |= LOADED; } + fclose(fp); + reset = vector_address - 4; irq = vector_address - 2; nmi = vector_address - 6; @@ -647,7 +653,7 @@ void binaryloadfile (void) { for (int j = 0; j < entry_count; j++) { - char *label = malloc(7); + char *label = emalloc (7); sprintf (label, "e_%04x", entry_address[j]); printf("label: %s\n", label); start_trace (entry_address[j], label); diff --git a/print.c b/print.c index 1a3f25c..17657a8 100644 --- a/print.c +++ b/print.c @@ -31,20 +31,17 @@ #include "dis.h" -char *strcpy(); -char *strcat(); - static char *lname (addr_t i, int offset_ok) { - static char buf[20]; + static char buf[40]; /* ~6-char label, +/-, long int */ char t; if (f[i] & NAMED) return(get_name(i)); if (f[i] & OFFSET) { - (void)strcpy(buf, get_name(i+offset[i])); - sprintf (buf + strlen (buf), "%c%ld", + sprintf (buf, "%s%c%ld", + get_name(i+offset[i]), (offset [i] <= 0) ? '+' : '-', labs (offset [i])); return (buf); @@ -168,7 +165,7 @@ int print_inst(addr_t addr) { int opcode; register struct info *ip; - int operand; + int operand = 0; opcode = getbyte(addr); ip = &optbl[opcode]; @@ -179,8 +176,6 @@ int print_inst(addr_t addr) switch(ip->nb) { case 1: - operand = 0; /* only to avoid "may be used - unitialized" warning */ break; case 2: operand = getbyte(addr); diff --git a/ref.c b/ref.c index 5a40156..134f9b2 100644 --- a/ref.c +++ b/ref.c @@ -71,7 +71,7 @@ void save_ref (addr_t refer, addr_t refee) struct ref_chain *rc; struct hashslot *hp; - rc = (struct ref_chain *)emalloc(sizeof(*rc)); + rc = emalloc(sizeof(*rc)); rc->who = refer; hp = hash(refee, 1); rc->next = hp->ref;