diff options
author | Michael Meskes <meskes@postgresql.org> | 2013-07-05 11:07:16 +0200 |
---|---|---|
committer | Michael Meskes <meskes@postgresql.org> | 2013-07-05 11:07:16 +0200 |
commit | 9ce9dfdb999960aa7596bb219db02ccdbe2da855 (patch) | |
tree | 8f52419892f85225890d1731141dc1ff0d214a34 /src | |
parent | 79e0f87a15643efa9a94e011da509746dbb96798 (diff) | |
download | postgresql-9ce9dfdb999960aa7596bb219db02ccdbe2da855.tar.gz postgresql-9ce9dfdb999960aa7596bb219db02ccdbe2da855.zip |
Apploed patch by MauMau <maumau307@gmail.com> to escape filenames in #line statements.
Diffstat (limited to 'src')
-rw-r--r-- | src/interfaces/ecpg/preproc/output.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/interfaces/ecpg/preproc/output.c b/src/interfaces/ecpg/preproc/output.c index 389a5272d44..616e8f04008 100644 --- a/src/interfaces/ecpg/preproc/output.c +++ b/src/interfaces/ecpg/preproc/output.c @@ -95,9 +95,22 @@ hashline_number(void) #endif ) { - char *line = mm_alloc(strlen("\n#line %d \"%s\"\n") + sizeof(int) * CHAR_BIT * 10 / 3 + strlen(input_filename)); - - sprintf(line, "\n#line %d \"%s\"\n", yylineno, input_filename); + /* "* 2" here is for escaping \s below */ + char *line = mm_alloc(strlen("\n#line %d \"%s\"\n") + sizeof(int) * CHAR_BIT * 10 / 3 + strlen(input_filename) * 2); + char *src, + *dest; + + sprintf(line, "\n#line %d \"", yylineno); + src = input_filename; + dest = line + strlen(line); + while (*src) + { + if (*src == '\\') + *dest++ = '\\'; + *dest++ = *src++; + } + *dest = '\0'; + strcat(dest, "\"\n"); return line; } |