scc

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

commit 1d8907008746478155d91a4e12962e41378c393a
parent aa4f2102e680077fd77bbdc9e1fd8a3503aecc5b
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; }