commit f071fe5eaccfa08807649ee69b8f8d7ee28a4505
Author: Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Thu Aug 27 21:31:13 2015 +0200
Commit: Roberto E. Vargas Caballero <[email protected]>
CommitDate: Thu Aug 27 21:31:13 2015 +0200
Validate size of array declarations
Array sizes must be possitive integers.
diff --git a/cc1/decl.c b/cc1/decl.c
index c92d546..b615c2f 100644
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -105,7 +105,16 @@ arydcl(struct declarators *dp)
}
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);