]> granicus.if.org Git - postgresql/commitdiff
Applied patch by MauMau <maumau307@gmail.com> to escape filenames in #line statements.
authorMichael Meskes <meskes@postgresql.org>
Fri, 5 Jul 2013 09:07:16 +0000 (11:07 +0200)
committerMichael Meskes <meskes@postgresql.org>
Sat, 6 Jul 2013 09:49:33 +0000 (11:49 +0200)
src/interfaces/ecpg/preproc/output.c

index 389a5272d44cce0b4dc8ec6ff16df58388783752..616e8f040086684e97746bf6b0aa71873ae835fb 100644 (file)
@@ -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;
        }