summaryrefslogtreecommitdiffstats
path: root/binutils-2.23/libiberty
diff options
context:
space:
mode:
authorRay Donnelly <mingw.android@gmail.com>2014-03-17 08:15:01 +0000
committerRay Donnelly <mingw.android@gmail.com>2014-03-17 12:11:09 +0000
commit99e61be119cf94aed94e96a1cc192b4733ed7c1d (patch)
tree3e5a9193f2c4c8b4b021e5c99311d9d59e19a4dd /binutils-2.23/libiberty
parent5a2caf34e4995860baf405552163df288000b7bf (diff)
downloadtoolchain_binutils-99e61be119cf94aed94e96a1cc192b4733ed7c1d.tar.gz
toolchain_binutils-99e61be119cf94aed94e96a1cc192b4733ed7c1d.tar.bz2
toolchain_binutils-99e61be119cf94aed94e96a1cc192b4733ed7c1d.zip
2.21-2.23: Only quote arguments in pex-win32.c that need it
.. it always quoted all arguments, irrespective of whether there was a need to. This means the 32k limit is getting hit more often than it needs to. Change-Id: I5fb427cc3ad6a00a8099d3ed0fce1f43ed027f78
Diffstat (limited to 'binutils-2.23/libiberty')
-rw-r--r--binutils-2.23/libiberty/pex-win32.c47
1 files changed, 38 insertions, 9 deletions
diff --git a/binutils-2.23/libiberty/pex-win32.c b/binutils-2.23/libiberty/pex-win32.c
index eae72c51..bd99584e 100644
--- a/binutils-2.23/libiberty/pex-win32.c
+++ b/binutils-2.23/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';