scc

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

commit a1512e6b29c48372f475827acafd7b657d0d20d9
parent 7e3fa9b203382ef638cae9bf9b4de9e01bdac836
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 12 Mar 2018 18:46:18 +0100

[nm/coff32] Fix string table retrieve

The loop was wrong and was generating wrong strings.

Diffstat:
Mnm/coff32.c | 14+++++++-------
Mtests/nm/execute/0001-z80.sh | 8+++++++-
Mtests/nm/execute/master.s | 12+++++++++---
3 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/nm/coff32.c b/nm/coff32.c @@ -85,14 +85,14 @@ getsname(char *fname, FILE *fp, SYMENT *ent) if (ferror(fp)) goto error; - s = xmalloc(1); - for (len = 0; (c = getc(fp)) != '\0'; len++) { - if (c == EOF) - goto error; - s = xrealloc(s, len+1); - s[len] = c; + s = NULL; + for (len = 1; (c = getc(fp)) != EOF; len++) { + s = xrealloc(s, len); + if ((s[len-1] = c) == '\0') + break; } - s[len] = '\0'; + if (c == EOF) + goto error; fsetpos(fp, &pos); return s; diff --git a/tests/nm/execute/0001-z80.sh b/tests/nm/execute/0001-z80.sh @@ -13,15 +13,21 @@ cat <<! > $tmp2 0000000000000000 b .bss 0000000000000000 d .data 0000000000000000 t .text -0000000000000001 B averylongbss  +0000000000000001 B averylongbss 0000000000000001 D averylongdata 0000000000000001 T averylongtext 0000000000000000 B bss1 0000000000000002 b bss3 +000000000000000a C bss4 +0000000000000012 C bss5 0000000000000000 D data1 0000000000000002 d data3 +000000000000000a C data4 +0000000000000012 C data5 0000000000000000 T text1 0000000000000002 t text3 +000000000000000a C text4 +0000000000000012 C text5 ! cmp $tmp1 $tmp2 diff --git a/tests/nm/execute/master.s b/tests/nm/execute/master.s @@ -1,23 +1,29 @@ - .globl text1,averylongtext + .globl text1,averylongtext,text5 .text .equ text2,4 text1: .byte 0 averylongtext: .byte 0 text3: .byte 0 + .comm text4,10 + .comm text5,18 - .globl data1,averylongdata + .globl data1,averylongdata,data5 .data .equ data2,5 data1: .byte 3 averylongdata: .byte 0 data3: .byte 0 + .comm data4,10 + .comm data5,18 - .globl bss1,averylongbss + .globl bss1,averylongbss,bss5 .bss .equ bss2,5 bss1: .byte 0 averylongbss: .byte 0 bss3: .byte 0 + .comm bss4,10 + .comm bss5,18