ref: db565b93a3e8db0e72be663d3cb6560ab96fc64f
parent: 1cd61f173ed9b75de10f8d8b6a68a8de8cc095cf
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sun Oct 31 13:28:35 EDT 2021
cc1: Fix escape in macro expansion Copymacro() was copying without worring about escape characters making the expansion of the macro wrong. .
--- a/src/cmd/cc/cc1/cpp.c
+++ b/src/cmd/cc/cc1/cpp.c
@@ -184,7 +184,7 @@
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 @@
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;