[hackers] [scc] Improve error recovery in init.c || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Tue, 19 Jan 2016 15:40:03 +0100 (CET)

commit e56b22693ff12207d5106ed3c9aab1ba77cbb096
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Tue Jan 19 12:18:41 2016 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Tue Jan 19 14:04:38 2016 +0100

    Improve error recovery in init.c

diff --git a/cc1/init.c b/cc1/init.c
index 93b4466..41b6829 100644
--- a/cc1/init.c
+++ b/cc1/init.c
_AT_@ -1,4 +1,5 @@
 
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
_AT_@ -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 {
_AT_@ -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) {
Received on Tue Jan 19 2016 - 15:40:03 CET

This archive was generated by hypermail 2.3.0 : Tue Jan 19 2016 - 15:48:25 CET