scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit f071fe5eaccfa08807649ee69b8f8d7ee28a4505
parent 138e890629e9b4059e62fd6111be6ec01afb97ec
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 27 Aug 2015 21:31:13 +0200

Validate size of array declarations

Array sizes must be possitive integers.

Diffstat:
cc1/decl.c | 11++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git 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);