From fbb22988150b98a3332a06e957154ac2bd6e4a35 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 8 Apr 2009 20:10:57 +0000 Subject: [PATCH] properly escape filenames when generating implicit #includes, this handles things like " in paths etc. Found by inspection. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68632 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/clang-cc/clang-cc.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp index d5c44cd078..ee90147e60 100644 --- a/tools/clang-cc/clang-cc.cpp +++ b/tools/clang-cc/clang-cc.cpp @@ -1011,7 +1011,10 @@ static void DefineBuiltinMacro(std::vector &Buf, const char *Macro, static void AddImplicitInclude(std::vector &Buf, const std::string &File){ const char *Inc = "#include \""; Buf.insert(Buf.end(), Inc, Inc+strlen(Inc)); - Buf.insert(Buf.end(), File.begin(), File.end()); + + // Escape double quotes etc. + std::string EscapedFile = Lexer::Stringify(File); + Buf.insert(Buf.end(), EscapedFile.begin(), EscapedFile.end()); Buf.push_back('"'); Buf.push_back('\n'); } @@ -1020,7 +1023,10 @@ static void AddImplicitIncludeMacros(std::vector &Buf, const std::string &File) { const char *Inc = "#__include_macros \""; Buf.insert(Buf.end(), Inc, Inc+strlen(Inc)); - Buf.insert(Buf.end(), File.begin(), File.end()); + + // Escape double quotes etc. + std::string EscapedFile = Lexer::Stringify(File); + Buf.insert(Buf.end(), EscapedFile.begin(), EscapedFile.end()); Buf.push_back('"'); Buf.push_back('\n'); } -- 2.50.1