shithub: scc

Download patch

ref: c4b4078dcb16f27f397c310e400559ea2ef26fed
parent: ffdf7436ae4c2a8b573a325d9ca3c7f0b475a149
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon Dec 12 11:13:21 EST 2016

[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.

--- a/cc1/types.c
+++ b/cc1/types.c
@@ -308,15 +308,17 @@
 
 	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;
+			}
 		}
 	}