summaryrefslogtreecommitdiffstats
path: root/llvm/lib/System
diff options
context:
space:
mode:
authorAnton Korobeynikov <asl@math.spbu.ru>2010-03-28 15:07:02 +0000
committerAnton Korobeynikov <asl@math.spbu.ru>2010-03-28 15:07:02 +0000
commitc2747d068e197e635d4b7ac71833c2cf658815c9 (patch)
treecb0910a4f406a852aa13f92950c8ffdd01d21c8f /llvm/lib/System
parent07f0adc2a6be5e00a0b5a1b87ec123cb357dead7 (diff)
downloadbcm5719-llvm-c2747d068e197e635d4b7ac71833c2cf658815c9.tar.gz
bcm5719-llvm-c2747d068e197e635d4b7ac71833c2cf658815c9.zip
Properly quote the quotes :) during cmdline construction on Windows.
Otherwise, e.g. in the invocation like clang -DFOO=\"bar\" FOO macro got the bar value, not "bar". Patch by Alexander Esilevich! llvm-svn: 99763
Diffstat (limited to 'llvm/lib/System')
-rw-r--r--llvm/lib/System/Win32/Program.inc34
1 files changed, 28 insertions, 6 deletions
diff --git a/llvm/lib/System/Win32/Program.inc b/llvm/lib/System/Win32/Program.inc
index a3b40d0e365..16bb28e17a2 100644
--- a/llvm/lib/System/Win32/Program.inc
+++ b/llvm/lib/System/Win32/Program.inc
@@ -138,6 +138,24 @@ static bool ArgNeedsQuotes(const char *Str) {
return Str[0] == '\0' || strchr(Str, ' ') != 0;
}
+
+/// ArgLenWithQuotes - Check whether argument needs to be quoted when calling
+/// CreateProcess and returns length of quoted arg with escaped quotes
+static unsigned int ArgLenWithQuotes(const char *Str) {
+ unsigned int len = ArgNeedsQuotes(Str) ? 2 : 0;
+
+ while (*Str != '\0') {
+ if (*Str == '\"')
+ ++len;
+
+ ++len;
+ ++Str;
+ }
+
+ return len;
+}
+
+
bool
Program::Execute(const Path& path,
const char** args,
@@ -165,9 +183,7 @@ Program::Execute(const Path& path,
// First, determine the length of the command line.
unsigned len = 0;
for (unsigned i = 0; args[i]; i++) {
- len += strlen(args[i]) + 1;
- if (ArgNeedsQuotes(args[i]))
- len += 2;
+ len += ArgLenWithQuotes(args[i]) + 1;
}
// Now build the command line.
@@ -176,12 +192,18 @@ Program::Execute(const Path& path,
for (unsigned i = 0; args[i]; i++) {
const char *arg = args[i];
- size_t len = strlen(arg);
+
bool needsQuoting = ArgNeedsQuotes(arg);
if (needsQuoting)
*p++ = '"';
- memcpy(p, arg, len);
- p += len;
+
+ while (*arg != '\0') {
+ if (*arg == '\"')
+ *p++ = '\\';
+
+ *p++ = *arg++;
+ }
+
if (needsQuoting)
*p++ = '"';
*p++ = ' ';
OpenPOWER on IntegriCloud