scc

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

commit 35755ad1c9f5cbba9db0ef500d20f73ce654c3c7
parent 662f5dda9ab4c51c2339dcde074ab76b5c49afb0
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 12 Dec 2016 16:13:21 +0100

[cc1] Do not allocate enum types in the hash

This was an error in mktype(), because at the beginning
all the enum (and struct and union) have 0 elements,
so it could reuse the same struct for different types
and since every type evolute in a different way it
could generate a data corruption.

Diffstat:
Mcc1/types.c | 20+++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/cc1/types.c b/cc1/types.c @@ -308,15 +308,17 @@ mktype(Type *tp, int op, TINT nelem, Type *pars[]) t = (op ^ (uintptr_t) tp>>3) & NR_TYPE_HASH-1; tbl = &typetab[t]; - for (bp = tbl; bp->h_next != tbl; bp = bp->h_next) { - if (eqtype(bp, &type, 0) && op != STRUCT && op != UNION) { - /* - * pars was allocated by the caller - * but the type already exists, so - * we have to deallocte it - */ - free(pars); - return bp; + if (op != STRUCT && op != UNION && op != ENUM) { + for (bp = tbl; bp->h_next != tbl; bp = bp->h_next) { + if (eqtype(bp, &type, 0)) { + /* + * pars was allocated by the caller + * but the type already exists, so + * we have to deallocte it + */ + free(pars); + return bp; + } } }