[hackers] [scc] [cc1] Fix character constants in macros || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Mon, 16 Jan 2017 13:32:47 +0100 (CET)

commit 4eff786be3921ff7e1fc90b57e7f0a8932a1fda1
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Mon Jan 16 13:31:48 2017 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Mon Jan 16 13:31:48 2017 +0100

    [cc1] Fix character constants in macros
    
    Character tokens were not taking a correct yytext, which
    was generating a problem in getdefs() because this function
    is based in taking the text of the tokens from yytext.

diff --git a/cc1/cpp.c b/cc1/cpp.c
index 0573fce..d8c4124 100644
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
_AT_@ -182,11 +182,10 @@ parsepars(char *buffer, char **listp, int nargs)
         return 1;
 }
 
-/* FIXME: characters in the definition break the macro definition */
 static size_t
 copymacro(char *buffer, char *s, size_t bufsiz, char *arglist[])
 {
- char prevc, c, *p, *arg, *bp = buffer;
+ char delim, prevc, c, *p, *arg, *bp = buffer;
         size_t size;
 
         for (prevc = '\0'; c = *s; prevc = c, ++s) {
_AT_@ -198,8 +197,13 @@ copymacro(char *buffer, char *s, size_t bufsiz, char *arglist[])
                                 ++s;
                 case '#':
                         break;
+ case '\'':
+ delim = '\'';
+ goto search_delim;
                 case '\"':
- for (p = s; *++s != '"'; )
+ delim = '"';
+ search_delim:
+ for (p = s; *++s != delim; )
                                 /* nothing */;
                         size = s - p + 1;
                         if (size > bufsiz)
diff --git a/cc1/lex.c b/cc1/lex.c
index d7e8aa3..2a0749b 100644
--- a/cc1/lex.c
+++ b/cc1/lex.c
_AT_@ -467,9 +467,11 @@ escape(void)
 static unsigned
 character(void)
 {
- static char c;
+ char c, *p;
         Symbol *sym;
+ size_t size;
 
+ p = input->p;
         if ((c = *++input->p) == '\\')
                 c = escape();
         else
_AT_@ -480,6 +482,10 @@ character(void)
         else
                 ++input->p;
 
+ size = input->p - p;
+ memcpy(yytext, p, size);
+ yytext[size] = '\0';
+
         sym = newsym(NS_IDEN, NULL);
         sym->u.i = c;
         sym->type = inttype;
Received on Mon Jan 16 2017 - 13:32:47 CET

This archive was generated by hypermail 2.3.0 : Mon Jan 16 2017 - 13:36:17 CET