[hackers] [scc] [cc1] Do not allocate enum types in the hash || Roberto E. Vargas Caballero
commit 35755ad1c9f5cbba9db0ef500d20f73ce654c3c7
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Mon Dec 12 16:13:21 2016 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Mon Dec 12 16:13:21 2016 +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.
diff --git a/cc1/types.c b/cc1/types.c
index 167d5a9..0d2375e 100644
--- a/cc1/types.c
+++ b/cc1/types.c
_AT_@ -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;
+ }
}
}
Received on Tue Dec 13 2016 - 17:59:10 CET
This archive was generated by hypermail 2.3.0
: Tue Dec 13 2016 - 18:00:24 CET