[llvm-commits] [llvm] r99763 - /llvm/trunk/lib/System/Win32/Program.inc
Anton Korobeynikov
asl at math.spbu.ru
Sun Mar 28 08:07:03 PDT 2010
Author: asl
Date: Sun Mar 28 10:07:02 2010
New Revision: 99763
URL: http://llvm.org/viewvc/llvm-project?rev=99763&view=rev
Log:
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!
Modified:
llvm/trunk/lib/System/Win32/Program.inc
Modified: llvm/trunk/lib/System/Win32/Program.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Win32/Program.inc?rev=99763&r1=99762&r2=99763&view=diff
==============================================================================
--- llvm/trunk/lib/System/Win32/Program.inc (original)
+++ llvm/trunk/lib/System/Win32/Program.inc Sun Mar 28 10:07:02 2010
@@ -138,6 +138,24 @@
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 @@
// 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 @@
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++ = ' ';
More information about the llvm-commits
mailing list