[hackers] [scc] [cc1] Fix parsing of function alike macros || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Wed, 11 May 2016 12:59:38 +0200 (CEST)

commit 0fc57e51871e09511d6135791773b7e0ba26aaf6
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Wed May 11 12:57:56 2016 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Wed May 11 12:57:56 2016 +0200

    [cc1] Fix parsing of function alike macros
    
    A macro is a function alike macro if just after the name of
    the macro there is a '('. Before this commit we were detecting
    this situation only looking for tokens, but in this case we
    need to check directly in the input line and see if '(' is
    not separated from the macro name.

diff --git a/cc1/cpp.c b/cc1/cpp.c
index af4f344..6d96635 100644
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
_AT_@ -293,16 +293,18 @@ substitute:
 static int
 getpars(Symbol *args[NR_MACROARG])
 {
- int n = -1;
+ int n, c;
         Symbol *sym;
 
- if (!accept('('))
- return n;
- ++n;
+ c = *input->p;
+ next();
+ if (c != '(')
+ return -1;
+ next(); /* skip the '(' */
         if (accept(')'))
- return n;
+ return 0;
 
- do {
+ for (n = 0; ; ++n) {
                 if (n == NR_MACROARG) {
                         cpperror("too much parameters in macro");
                         return NR_MACROARG;
_AT_@ -313,9 +315,11 @@ getpars(Symbol *args[NR_MACROARG])
                 }
                 sym = install(NS_IDEN, yylval.sym);
                 sym->flags |= SUSED;
- args[n++] = sym;
+ args[n] = sym;
                 next();
- } while (accept(','));
+ if (!accept(','))
+ break;
+ }
         expect(')');
 
         return n;
_AT_@ -399,7 +403,6 @@ define(void)
         }
 
         namespace = NS_IDEN; /* Avoid polution in NS_CPP */
- next();
         if ((n = getpars(args)) == NR_MACROARG)
                 goto delete;
         sprintf(buff, "%02d#", n);
Received on Wed May 11 2016 - 12:59:38 CEST

This archive was generated by hypermail 2.3.0 : Wed May 11 2016 - 13:00:23 CEST