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

From: <git_AT_suckless.org>
Date: Fri, 17 Feb 2017 10:52:56 +0100 (CET)

commit 98d67510f4516bb2a156ca2aa50cf2ea9a8731c9
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 10:51:31 2017 +0100

    [libc] Fix multiple void function parameter check

diff --git a/cc1/decl.c b/cc1/decl.c
index 32b632d..613dfaa 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 - 10:52:56 CET

This archive was generated by hypermail 2.3.0 : Fri Feb 17 2017 - 11:00:38 CET