commit 8b96dd8a8d2e271d27d9407d4e847f1d3f194e13
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Sat Oct 3 10:37:47 2015 +0200
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Sat Oct 3 12:12:45 2015 +0200

    Protect @ and $ in strings when expand macros
    
    @ and $ are used in the preprocessor to mark
    arguments and concatenation, but they can
    appear in strings, so we have to handle
    strings in copymacro()

diff --git a/cc1/cpp.c b/cc1/cpp.c
index 355ec2c..88f51f6 100644
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -145,28 +145,39 @@ 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, *arg, *bp = buffer;
+       char prevc, c, *p, *arg, *bp = buffer;
+       size_t size;
 
        for (prevc = '\0'; c = *s; prevc = c, ++s) {
                if (c != '@') {
-                       if (c == '#')
-                               continue;
-                       if (c == '$') {
+                       switch (c) {
+                       case '$':
                                while (bp[-1] == ' ')
                                        --bp, ++bufsiz;
                                while (s[1] == ' ')
                                        ++s;
+                       case '#':
+                               continue;
+                       case '\"':
+                               for (p = s; *++s != '"'; )
+                                       /* nothing */;
+                               size = s - p + 1;
+                               if (size > bufsiz)
+                                       goto expansion_too_long;
+                               memcpy(bp, p, size);
+                               bufsiz -= size;
+                               bp += size;
                                continue;
+                       // case '\'';
                        }
                        if (bufsiz-- == 0)
                                goto expansion_too_long;
                        *bp++ = c;
                } else {
-                       size_t size;
-
                        if (prevc == '#')
                                bufsiz -= 2;
                        arg = arglist[atoi(++s)];

Reply via email to