Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9ce9dfd

Browse files
author
Michael Meskes
committed
Apploed patch by MauMau <maumau307@gmail.com> to escape filenames in #line statements.
1 parent 79e0f87 commit 9ce9dfd

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/interfaces/ecpg/preproc/output.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,22 @@ hashline_number(void)
9595
#endif
9696
)
9797
{
98-
char *line = mm_alloc(strlen("\n#line %d \"%s\"\n") + sizeof(int) * CHAR_BIT * 10 / 3 + strlen(input_filename));
99-
100-
sprintf(line, "\n#line %d \"%s\"\n", yylineno, input_filename);
98+
/* "* 2" here is for escaping \s below */
99+
char *line = mm_alloc(strlen("\n#line %d \"%s\"\n") + sizeof(int) * CHAR_BIT * 10 / 3 + strlen(input_filename) * 2);
100+
char *src,
101+
*dest;
102+
103+
sprintf(line, "\n#line %d \"", yylineno);
104+
src = input_filename;
105+
dest = line + strlen(line);
106+
while (*src)
107+
{
108+
if (*src == '\\')
109+
*dest++ = '\\';
110+
*dest++ = *src++;
111+
}
112+
*dest = '\0';
113+
strcat(dest, "\"\n");
101114

102115
return line;
103116
}

0 commit comments

Comments
 (0)