scc

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

commit e532ed7566f8402a50b252bdc1496f9cdf87ea52
parent 3af210a83dd2456a57cc84828ccd5d9c44af3aea
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 20 Feb 2019 08:27:19 +0000

[ld] Solves several problems in the main loop of loadlib()

The code could generate infinite loops in the way
that it was written and the condition for the definition
of the symbol was the opposite.

Diffstat:
Msrc/cmd/ld.c | 13++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/src/cmd/ld.c b/src/cmd/ld.c @@ -341,32 +341,31 @@ loadlib(FILE *fp) return; } - for (loaded = 0; moreundef(); loaded = 0) { + for (loaded = 1; moreundef() && loaded; ) { + loaded = 0; for (dp = def; dp; dp = dp->next) { sym = lookup(dp->name, NOINSTALL); - if (!sym || !sym->def) + if (!sym || sym->def) continue; if (fseek(fp, dp->offset, SEEK_SET) == EOF) { error(errstr()); - break; + goto clean; } if ((t = objtype(fp, NULL)) == -1) { error("library file corrupted"); - break; + goto clean; } if (t != bintype) { error("incompatible library"); - break; + goto clean; } newobject(fp, t, OUTLIB); loaded = 1; } - if (!loaded) - break; } clean: free(def);