commit 5207a71d38e39164095f0f2c5e3da71901c00335 parent a4c8e1174b66b4f23599fcc2002266ec8e09940f Author: Roberto E. Vargas Caballero <k0ga@shike2.com> Date: Sun, 10 Sep 2017 08:09:46 +0200 [as] Fix memory allocation in lookup() Diffstat:
M | as/emit.c | | | 15 | ++++++++------- |
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/as/emit.c b/as/emit.c @@ -41,29 +41,30 @@ Symbol * lookup(char *name) { unsigned h; - Symbol *sym; + Symbol *sym, **list; int c; char *t, *s; - s = name; - for (h = 0; c = *s; ++s) + h = 0; + for (s = name; c = *s; ++s) h = h*33 ^ c; h &= HASHSIZ-1; c = *name; - for (sym = hashtbl[h]; sym; sym = sym->next) { + list = &hashtbl[h]; + for (sym = *list; sym; sym = sym->next) { t = sym->name; if (c == *t && !strcmp(t, name)) return sym; } - sym = xmalloc(sizeof(sym)); + sym = xmalloc(sizeof(*sym)); sym->name = xstrdup(name); sym->type = FUNDEF; sym->desc = 0; sym->value = 0; - sym->next = hashtbl[h]; - hashtbl[h] = sym; + sym->next = *list; + *list = sym; return sym; }