commit db565b93a3e8db0e72be663d3cb6560ab96fc64f
parent 1cd61f173ed9b75de10f8d8b6a68a8de8cc095cf
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Sun, 31 Oct 2021 17:28:35 +0100
cc1: Fix escape in macro expansion
Copymacro() was copying without worring about escape characters
making the expansion of the macro wrong.
.
Diffstat:
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/src/cmd/cc/cc1/cpp.c b/src/cmd/cc/cc1/cpp.c
@@ -184,7 +184,7 @@ parsepars(char *buffer, char **listp, int nargs)
static size_t
copymacro(char *buffer, char *s, size_t bufsiz, char *arglist[])
{
- int delim, prevc, c;
+ int delim, prevc, c, esc;
char *p, *arg, *bp = buffer;
size_t size;
@@ -203,8 +203,16 @@ copymacro(char *buffer, char *s, size_t bufsiz, char *arglist[])
case '\"':
delim = '"';
search_delim:
- for (p = s; *++s != delim; )
- ;
+ esc = 0;
+ p = s;
+ for (++s; c = *s; ++s) {
+ if (c == '\\' && !esc)
+ esc = 1;
+ else if (c == delim &&!esc)
+ break;
+ else
+ esc = 0;
+ }
size = s - p + 1;
if (size > bufsiz)
goto expansion_too_long;