X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=libiberty%2Fargv.c;h=6a72208d8458e7d1650d5d2831c770ed7a8c7195;hb=a1d1fa3e417b4bd8e79e2a731f9c6089e2d5f747;hp=c544dad73eec8f18c2725fd25b88a033fec223fc;hpb=e495212d229d58eb4d70c94d7f828a04c386c3b2;p=deliverable%2Fbinutils-gdb.git diff --git a/libiberty/argv.c b/libiberty/argv.c index c544dad73e..6a72208d84 100644 --- a/libiberty/argv.c +++ b/libiberty/argv.c @@ -1,5 +1,5 @@ /* Create and destroy argument vectors (argv's) - Copyright (C) 1992-2017 Free Software Foundation, Inc. + Copyright (C) 1992-2020 Free Software Foundation, Inc. Written by Fred Fish @ Cygnus Support This file is part of the libiberty library. @@ -327,6 +327,14 @@ writeargv (char * const *argv, FILE *f) arg++; } + /* Write out a pair of quotes for an empty argument. */ + if (arg == *argv) + if (EOF == fputs ("\"\"", f)) + { + status = 1; + goto done; + } + if (EOF == fputc ('\n', f)) { status = 1; @@ -367,8 +375,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,12 +457,14 @@ 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; while (file_argv[file_argc]) ++file_argc; + /* Free the original option's memory. */ + free ((*argvp)[i]); /* Now, insert FILE_ARGV into ARGV. The "+1" below handles the NULL terminator at the end of ARGV. */ *argvp = ((char **)