scc

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

commit 17a2ac09a4306129d5ec039ff52f74a48b226e48
parent 3a079f24c514f9783a7dd15e85a02eae4c25e695
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 21 Aug 2019 11:49:10 +0100

[ld] Fix merge()

We were incrementing the number of sections per segment in every
iteration instead of every match. This was creating NULL entries
in the section array of every segment.

Diffstat:
Msrc/cmd/ld/pass2.c | 8++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/cmd/ld/pass2.c b/src/cmd/ld/pass2.c @@ -36,17 +36,17 @@ static void merge(Segment *seg) { Section *sec, **p; - int n; + int n = 0; - for (n = 0, sec = sechead; sec; sec = sec->next, ++n) { + for (sec = sechead; sec; sec = sec->next) { if (sec->type != seg->type) continue; - p = realloc(seg->sections, n * sizeof(*p)); + p = realloc(seg->sections, (n+1) * sizeof(*p)); if (!p) { error("ou of memory"); exit(EXIT_FAILURE); } - p[n] = sec; + p[n++] = sec; seg->sections = p; seg->size += sec->size; }