scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit 443838bfc5a8c6c96e32e0d9ec39a016fc636d0e
parent 591e6fb0d84ddc201810b22252b79f69ad409457
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 27 Apr 2018 15:07:24 +0200

[nm/coff32] Simplify string table handling

Diffstat:
Mnm/coff32.c | 28++++++++++------------------
1 file changed, 10 insertions(+), 18 deletions(-)

diff --git a/nm/coff32.c b/nm/coff32.c @@ -16,7 +16,7 @@ static char sccsid[] = "@(#) ./nm/coff.c"; #include "nm.h" static int (*unpack)(unsigned char *, char *, ...); -static long stringtbl, symtbl, sectbl; +static long strtbl, symtbl, sectbl; static SCNHDR *sections; static struct symbol *syms; static size_t nsect, nsyms; @@ -75,9 +75,10 @@ getsname(char *fname, FILE *fp, SYMENT *ent) s[len] = '\0'; return memcpy(s, ent->n_name, len); } - + + /* TODO: read the string table in memory before reading symbols */ fgetpos(fp, &pos); - fseek(fp, stringtbl, SEEK_SET); + fseek(fp, strtbl, SEEK_SET); fseek(fp, ent->n_offset, SEEK_CUR); if (ferror(fp)) @@ -247,23 +248,12 @@ nm(char *fname, char *member, FILE *fp) { unsigned char buff[FILHSZ]; FILHDR hdr; - unsigned magic; long pos = ftell(fp); if (fread(buff, FILHSZ, 1, fp) != 1) { - if (!ferror(fp)) - return 0; - die("nm: %s: %s", fname, strerror(errno)); - } - - magic = buff[0] | buff[1] << 8; - - switch (magic) { - case COFF_Z80MAGIC: - unpack = lunpack; - break; - default: - abort(); + if (ferror(fp)) + die("nm: %s: %s", fname, strerror(errno)); + die("nm: %s: corrupted file", fname); } getfhdr(buff, &hdr); @@ -273,7 +263,7 @@ nm(char *fname, char *member, FILE *fp) } /* TODO: Check overflow */ - stringtbl = pos + hdr.f_symptr + hdr.f_nsyms* SYMESZ; + strtbl = pos + hdr.f_symptr + hdr.f_nsyms* SYMESZ; symtbl = pos + hdr.f_symptr; sectbl = pos + FILHSZ + hdr.f_opthdr; @@ -308,8 +298,10 @@ probe(char *fname, char *member, FILE *fp) switch (magic) { case COFF_Z80MAGIC: + unpack = lunpack; return 1; default: + unpack = NULL; return 0; } }