ref: ad731a5c07b5a8e5584289905e8fd461a38bd831
parent: bc25f9e6251bd9f8d5330988e0965fde4588d988
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Mar 12 14:46:18 EDT 2018
[nm/coff32] Fix string table retrieve The loop was wrong and was generating wrong strings.
--- a/nm/coff32.c
+++ b/nm/coff32.c
@@ -85,14 +85,14 @@
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;
--- a/tests/nm/execute/0001-z80.sh
+++ b/tests/nm/execute/0001-z80.sh
@@ -13,15 +13,21 @@
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
--- a/tests/nm/execute/master.s
+++ b/tests/nm/execute/master.s
@@ -1,4 +1,4 @@
- .globl text1,averylongtext
+ .globl text1,averylongtext,text5
.text
.equ text2,4
text1: .byte 0
@@ -5,8 +5,10 @@
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
@@ -13,8 +15,10 @@
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
@@ -21,3 +25,5 @@
averylongbss:
.byte 0
bss3: .byte 0
+ .comm bss4,10
+ .comm bss5,18