[hackers] [scc] Add error recovery in arguments() || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Fri, 4 Sep 2015 20:22:39 +0200 (CEST)

commit 677014ec4c6f86d6a2d8502c4e8bd972919ce0ec
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Fri Sep 4 19:17:25 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Fri Sep 4 19:17:25 2015 +0200

    Add error recovery in arguments()

diff --git a/cc1/expr.c b/cc1/expr.c
index 55ad6b1..b8c9f1d 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
_AT_@ -540,7 +540,7 @@ static Node *assign(void);
 static Node *
 arguments(Node *np)
 {
- int n;
+ int n, toomany;;
         Node *par = NULL, *arg;
         Type **targs, *tp = np->type;
 
_AT_@ -554,27 +554,32 @@ arguments(Node *np)
 
         expect('(');
 
- if ((n = tp->n.elem) > 0) {
- do {
- if ((arg = eval(assign())) == NULL)
- unexpected();
- if ((arg = convert(arg, *targs++, 0)) == NULL)
- goto bad_type;
+ n = tp->n.elem;
+ if (yytoken == ')')
+ goto no_pars;
+ toomany = 0;
+
+ do {
+ arg = eval(assign());
+ if (--n < 0 && !toomany) {
+ errorp("too many arguments in function call");
+ toomany = 1;
+ continue;
+ }
+ if ((arg = convert(arg, *targs, 0)) != NULL) {
                         par = node(OPAR, arg->type, par, arg);
- } while (--n && accept(','));
- }
+ continue;
+ }
+ errorp("incompatible type for argument %d in function call",
+ tp->n.elem - n + 1);
+ } while (accept(','));
 
+no_pars:
         if (n > 0)
- error("too few arguments in function call");
- if (yytoken == ',')
- error("too many arguments in function call");
+ errorp("too few arguments in function call");
 
         expect(')');
         return node(OCALL, np->type->type, np, par);
-
-bad_type:
- error("incompatible type for argument %d in function call",
- tp->n.elem - n + 1);
 }
 
 static Node *
Received on Fri Sep 04 2015 - 20:22:39 CEST

This archive was generated by hypermail 2.3.0 : Fri Sep 04 2015 - 20:24:22 CEST