[hackers] [scc] Avoid multiple message errors in Case() || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Sat, 28 Nov 2015 16:20:43 +0100 (CET)

commit 9e29fc687fadb6d0ef18e986825c1b788ddd7284
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Sat Nov 28 16:12:53 2015 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Sat Nov 28 16:20:29 2015 +0100

    Avoid multiple message errors in Case()
    
    It is anonnying to get a full page of the same error,
    so it is a good idea to mark the error like already
    printed. There is no problems with the value of nr,
    since this field is only used to generate this error.

diff --git a/cc1/stmt.c b/cc1/stmt.c
index 244aabd..65a0a15 100644
--- a/cc1/stmt.c
+++ b/cc1/stmt.c
_AT_@ -242,15 +242,17 @@ Case(Symbol *lbreak, Symbol *lcont, Caselist *lswitch)
         if ((np = iconstexpr()) == NULL)
                 errorp("case label does not reduce to an integer constant");
         expect(':');
- if (lswitch) {
- pcase = xmalloc(sizeof(*pcase));
- pcase->expr = np;
- pcase->next = lswitch->head;
- emit(OLABEL, pcase->label = newlabel());
- lswitch->head = pcase;
- if (++lswitch->nr == NR_SWITCH)
+ if (lswitch && lswitch->nr >= 0) {
+ if (++lswitch->nr == NR_SWITCH) {
                         errorp("too case labels for a switch statement");
- /* TODO: Avoid repetion of this error for the same switch */
+ lswitch->nr = -1;
+ } else {
+ pcase = xmalloc(sizeof(*pcase));
+ pcase->expr = np;
+ pcase->next = lswitch->head;
+ emit(OLABEL, pcase->label = newlabel());
+ lswitch->head = pcase;
+ }
         }
         stmt(lbreak, lcont, lswitch);
 }
Received on Sat Nov 28 2015 - 16:20:43 CET

This archive was generated by hypermail 2.3.0 : Sat Nov 28 2015 - 16:24:14 CET