From bb2f42b1caa59cbb7eaf86a9b9dad78621ce0ad9 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 29 Sep 1993 01:29:31 +0000 Subject: [PATCH] (quote_string): New function. (special_symbol): Use it to properly quote special chars in __FILE__. From-SVN: r5526 --- gcc/cccp.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/gcc/cccp.c b/gcc/cccp.c index f8001c4f825..a73ef1b786d 100644 --- a/gcc/cccp.c +++ b/gcc/cccp.c @@ -308,6 +308,7 @@ static char *macarg (); static U_CHAR *skip_to_end_of_comment (); static U_CHAR *skip_quoted_string (); static U_CHAR *skip_paren_group (); +static void quote_string (); static char *check_precompiled (); /* static struct macrodef create_definition (); [moved below] */ @@ -3663,8 +3664,8 @@ special_symbol (hp, op) if (string) { - buf = (char *) alloca (3 + strlen (string)); - sprintf (buf, "\"%s\"", string); + buf = (char *) alloca (3 + 2 * strlen (string)); + quote_string (buf, string); } else buf = "\"\""; @@ -6907,6 +6908,31 @@ skip_quoted_string (bp, limit, start_line, count_newlines, backslash_newlines_p, return bp; } +/* Place into DST a quoted string representing the string SRC. */ +static void +quote_string (dst, src) + char *dst, *src; +{ + char c; + + for (*dst++ = '\"'; ; *dst++ = c) + switch ((c = *src++)) + { + case '\n': + c = 'n'; + /* fall through */ + case '\"': + case '\\': + *dst++ = '\\'; + break; + + case '\0': + *dst++ = '\"'; + *dst = '\0'; + return; + } +} + /* Skip across a group of balanced parens, starting from IP->bufp. IP->bufp is updated. Use this with IP->bufp pointing at an open-paren. -- 2.30.2