ref: e56b22693ff12207d5106ed3c9aab1ba77cbb096
parent: 3a13451527967209d4e2e9d8bf8248659bfafb3f
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Jan 19 07:18:41 EST 2016
Improve error recovery in init.c
--- 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 @@
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,8 +241,11 @@
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);
@@ -248,8 +252,10 @@
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) {--
⑨