[hackers] [scc] [cc1] Fix multiple void function parameter check || Quentin Rameau

From: <git_AT_suckless.org>
Date: Fri, 17 Feb 2017 23:06:58 +0100 (CET)

commit e44d78d4ad53b34dfe71378974a9208022a5e784
Author: Quentin Rameau <quinq_AT_fifth.space>
AuthorDate: Thu Feb 16 19:18:00 2017 +0100
Commit: Quentin Rameau <quinq_AT_fifth.space>
CommitDate: Fri Feb 17 22:51:32 2017 +0100

    [cc1] Fix multiple void function parameter check

diff --git a/cc1/decl.c b/cc1/decl.c
index aa55dda..d84f2d1 100644
--- a/cc1/decl.c
+++ b/cc1/decl.c
_AT_@ -166,11 +166,7 @@ parameter(struct decl *dcl)
 
         switch (tp->op) {
         case VOID:
- if (n != 0 || (funtp->prop & TK_R)) {
- errorp("incorrect void parameter");
- return NULL;
- }
- funtp->n.elem = -1;
+ funtp->n.elem = 1;
                 if (dcl->sclass)
                         errorp("void as unique parameter may not be qualified");
                 return NULL;
_AT_@ -246,41 +242,30 @@ ansifun(Type *tp, Type *types[], Symbol *syms[], int *ntypes, int *nsyms)
 {
         int npars = 0;
         Symbol *sym;
- int toomany = 0, toovoid = 0;
+ int toomany = 0, voidparam = 0;
 
         do {
- if (npars == -1 && !toovoid) {
- errorp("'void' must be the only parameter");
- toovoid = 1;
- }
+ ++npars;
                 if (accept(ELLIPSIS)) {
- if (npars == 0)
+ if (npars < 2)
                                 errorp("a named argument is requiered before '...'");
- ++npars;
                         *syms = NULL;
                         *types++ = ellipsistype;
- break;
- }
- if ((sym = dodcl(NOREP, parameter, NS_IDEN, tp)) == NULL)
- continue;
- if (tp->n.elem == -1) {
- npars = -1;
- continue;
- }
- if (npars < NR_FUNPARAM) {
+ } else if ((sym = dodcl(NOREP, parameter, NS_IDEN, tp)) == NULL) {
+ if (tp->n.elem == 1)
+ voidparam = 1;
+ } else if (npars < NR_FUNPARAM) {
                         *syms++ = sym;
                         *types++ = sym->type;
- ++npars;
- continue;
- }
- if (!toomany) {
+ } else if (!toomany) {
                         errorp("too many parameters in function definition");
                         toomany = 1;
                 }
+ if (npars == 2 && voidparam)
+ errorp("'void' must be the only parameter");
         } while (accept(','));
 
- *nsyms = npars;
- *ntypes = npars;
+ *nsyms = *ntypes = voidparam ? 0 : npars;
 }
 
 static void
Received on Fri Feb 17 2017 - 23:06:58 CET

This archive was generated by hypermail 2.3.0 : Fri Feb 17 2017 - 23:12:39 CET