* [PATCH] expandargv: fix check for dynamic allocation of argument vector
@ 2017-12-30 19:46 Daniel van Gerpen
2018-01-10 23:06 ` Jeff Law
0 siblings, 1 reply; 2+ messages in thread
From: Daniel van Gerpen @ 2017-12-30 19:46 UTC (permalink / raw)
To: gcc-patches
When the code interpolates the contents of response files, the
argument vector is reallocated to the new size. This only works
if it was dynamically allocated once before -- we do not want to
mess with the argv memory given to us by the init code.
The code tried to detect this with a flag, but that was never
written to, leading to multiple dynamic allocations -- one
for each response file.
---
libiberty/argv.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/libiberty/argv.c b/libiberty/argv.c
index bdd4ace4cb6..fa88e50e894 100644
--- a/libiberty/argv.c
+++ b/libiberty/argv.c
@@ -367,8 +367,8 @@ expandargv (int *argcp, char ***argvp)
{
/* The argument we are currently processing. */
int i = 0;
- /* Non-zero if ***argvp has been dynamically allocated. */
- int argv_dynamic = 0;
+ /* To check if ***argvp has been dynamically allocated. */
+ char ** const original_argv = *argvp;
/* Limit the number of response files that we parse in order
to prevent infinite recursion. */
unsigned int iteration_limit = 2000;
@@ -449,7 +449,7 @@ expandargv (int *argcp, char ***argvp)
/* Parse the string. */
file_argv = buildargv (buffer);
/* If *ARGVP is not already dynamically allocated, copy it. */
- if (!argv_dynamic)
+ if (*argvp == original_argv)
*argvp = dupargv (*argvp);
/* Count the number of arguments. */
file_argc = 0;
--
2.11.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] expandargv: fix check for dynamic allocation of argument vector
2017-12-30 19:46 [PATCH] expandargv: fix check for dynamic allocation of argument vector Daniel van Gerpen
@ 2018-01-10 23:06 ` Jeff Law
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2018-01-10 23:06 UTC (permalink / raw)
To: Daniel van Gerpen, gcc-patches
On 12/30/2017 12:46 PM, Daniel van Gerpen wrote:
>
>
> When the code interpolates the contents of response files, the
> argument vector is reallocated to the new size. This only works
> if it was dynamically allocated once before -- we do not want to
> mess with the argv memory given to us by the init code.
>
> The code tried to detect this with a flag, but that was never
> written to, leading to multiple dynamic allocations -- one
> for each response file.
> ---
> libiberty/argv.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
THanks. I created a suitable ChangeLog entry and committed your patch
to the trunk.
Jeff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-01-10 22:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-30 19:46 [PATCH] expandargv: fix check for dynamic allocation of argument vector Daniel van Gerpen
2018-01-10 23:06 ` Jeff Law
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).