summaryrefslogtreecommitdiffstats
path: root/binutils-2.24/libiberty
diff options
context:
space:
mode:
authorRay Donnelly <mingw.android@gmail.com>2014-04-14 14:30:04 -0700
committerAndrew Hsieh <andrewhsieh@google.com>2014-04-14 14:54:03 -0700
commit57fbbfbda5a77b558c24a44e7eed8c4030c31bcd (patch)
treed36beda682af08362b04012c3a4d9a98ec51f4d8 /binutils-2.24/libiberty
parent160ce55a90bcdcb3000d74805795969edc3f8422 (diff)
downloadtoolchain_binutils-57fbbfbda5a77b558c24a44e7eed8c4030c31bcd.tar.gz
toolchain_binutils-57fbbfbda5a77b558c24a44e7eed8c4030c31bcd.tar.bz2
toolchain_binutils-57fbbfbda5a77b558c24a44e7eed8c4030c31bcd.zip
[2.24] Only quote arguments in pex-win32.c that need it
See 99e61be119cf94aed94e96a1cc192b4733ed7c1d Change-Id: I8d21ba308aa4d1e31a908b16f4e0e3168d7b8787
Diffstat (limited to 'binutils-2.24/libiberty')
-rw-r--r--binutils-2.24/libiberty/pex-win32.c47
1 files changed, 38 insertions, 9 deletions
diff --git a/binutils-2.24/libiberty/pex-win32.c b/binutils-2.24/libiberty/pex-win32.c
index eae72c51..bd99584e 100644
--- a/binutils-2.24/libiberty/pex-win32.c
+++ b/binutils-2.24/libiberty/pex-win32.c
@@ -340,17 +340,26 @@ argv_to_cmdline (char *const *argv)
char *p;
size_t cmdline_len;
int i, j, k;
+ int needs_quotes;
cmdline_len = 0;
for (i = 0; argv[i]; i++)
{
- /* We quote every last argument. This simplifies the problem;
- we need only escape embedded double-quotes and immediately
+ /* We only quote arguments that contain spaces, \n \t \v or " characters
+ to prevent wasting 2 chars per argument of the CreateProcess 32k char limit
+ We need only escape embedded double-quotes and immediately
preceeding backslash characters. A sequence of backslach characters
that is not follwed by a double quote character will not be
escaped. */
+ needs_quotes = 0;
for (j = 0; argv[i][j]; j++)
{
+ if (argv[i][j] == ' ' || argv[i][j] == '\n' ||
+ argv[i][j] == '\t' || argv[i][j] == '"' )
+ {
+ needs_quotes = 1;
+ }
+
if (argv[i][j] == '"')
{
/* Escape preceeding backslashes. */
@@ -362,16 +371,33 @@ argv_to_cmdline (char *const *argv)
}
/* Trailing backslashes also need to be escaped because they will be
followed by the terminating quote. */
- for (k = j - 1; k >= 0 && argv[i][k] == '\\'; k--)
- cmdline_len++;
+ if (needs_quotes)
+ {
+ for (k = j - 1; k >= 0 && argv[i][k] == '\\'; k--)
+ cmdline_len++;
+ }
cmdline_len += j;
- cmdline_len += 3; /* for leading and trailing quotes and space */
+ cmdline_len += 1 + (needs_quotes<<1); /* for leading and trailing quotes and space */
}
cmdline = XNEWVEC (char, cmdline_len);
p = cmdline;
for (i = 0; argv[i]; i++)
{
- *p++ = '"';
+ needs_quotes = 0;
+ for (j = 0; argv[i][j]; j++)
+ {
+ if (argv[i][j] == ' ' || argv[i][j] == '\n' ||
+ argv[i][j] == '\t' || argv[i][j] == '"' )
+ {
+ needs_quotes = 1;
+ break;
+ }
+ }
+
+ if (needs_quotes)
+ {
+ *p++ = '"';
+ }
for (j = 0; argv[i][j]; j++)
{
if (argv[i][j] == '"')
@@ -382,9 +408,12 @@ argv_to_cmdline (char *const *argv)
}
*p++ = argv[i][j];
}
- for (k = j - 1; k >= 0 && argv[i][k] == '\\'; k--)
- *p++ = '\\';
- *p++ = '"';
+ if (needs_quotes)
+ {
+ for (k = j - 1; k >= 0 && argv[i][k] == '\\'; k--)
+ *p++ = '\\';
+ *p++ = '"';
+ }
*p++ = ' ';
}
p[-1] = '\0';