shithub: scc

Download patch

ref: f071fe5eaccfa08807649ee69b8f8d7ee28a4505
parent: 138e890629e9b4059e62fd6111be6ec01afb97ec
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu Aug 27 17:31:13 EDT 2015

Validate size of array declarations

Array sizes must be possitive integers.

--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -105,7 +105,16 @@
 	}
 	expect(']');
 
-	n = (np == NULL) ? 0 : np->sym->u.i;
+	if (np != NULL) {
+		n = np->sym->u.i;
+		if (n  == 0 || n < 0) {
+			errorp("array size is not a positive number");
+			n = 1;
+		}
+	} else {
+		n = 0;
+	}
+
 	freetree(np);
 
 	push(dp, ARY, n);