From: Daniel Dunbar Date: Sat, 20 Mar 2010 08:01:53 +0000 (+0000) Subject: Driver: Fix -### to quote shell special characters, following gcc. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b86c5fc7393f61221686fc56e992ca409dee2a50;p=clang Driver: Fix -### to quote shell special characters, following gcc. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99053 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Driver/Compilation.cpp b/lib/Driver/Compilation.cpp index b819cda89c..98c6374425 100644 --- a/lib/Driver/Compilation.cpp +++ b/lib/Driver/Compilation.cpp @@ -61,10 +61,21 @@ void Compilation::PrintJob(llvm::raw_ostream &OS, const Job &J, OS << " \"" << C->getExecutable() << '"'; for (ArgStringList::const_iterator it = C->getArguments().begin(), ie = C->getArguments().end(); it != ie; ++it) { - if (Quote) - OS << " \"" << *it << '"'; - else - OS << ' ' << *it; + OS << ' '; + if (!Quote) { + OS << *it; + continue; + } + + // Quote the argument and escape shell special characters; this isn't + // really complete but is good enough. + OS << '"'; + for (const char *s = *it; *s; ++s) { + if (*s == '"' || *s == '\\' || *s == '$') + OS << '\\'; + OS << *s; + } + OS << '"'; } OS << Terminator; } else if (const PipedJob *PJ = dyn_cast(&J)) {