scc

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

commit e56b22693ff12207d5106ed3c9aab1ba77cbb096
parent 3a13451527967209d4e2e9d8bf8248659bfafb3f
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 19 Jan 2016 12:18:41 +0100

Improve error recovery in init.c

Diffstat:
cc1/init.c | 14++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/cc1/init.c b/cc1/init.c @@ -1,4 +1,5 @@ +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -110,7 +111,7 @@ mkcompound(Init *ip) if ((n = ip->max) == 0) { v = NULL; - } else if (n >= n * sizeof(*v)) { + } else if (n > SIZE_MAX / sizeof(*v)) { errorp("compound literal too big"); return constnode(zero); } else { @@ -240,16 +241,21 @@ initializer(Symbol *sym, Type *tp) Node *np; int flags = sym->flags; - if (tp->op == FTN) - errorp("function '%s' is initialized like a variable", sym->name); + if (tp->op == FTN) { + errorp("function '%s' is initialized like a variable", + sym->name); + tp = inttype; + } np = initialize(tp); emit(ODECL, sym); if (flags & ISDEFINED) { errorp("redeclaration of '%s'", sym->name); } else if ((flags & (ISGLOBAL|ISLOCAL|ISPRIVATE)) != 0) { - if (!np->constant) + if (!np->constant) { errorp("initializer element is not constant"); + return; + } emit(OINIT, np); sym->flags |= ISDEFINED; } else if ((flags & (ISEXTERN|ISTYPEDEF)) != 0) {