scc

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

commit 39dff9f7b0cb26421d0b67fc003fdda8db867e0b
parent 88ed18b6b1014546e25583c8d2372ba8030e1bf8
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);