]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
opts-common.c (prune_options): Ensure replacement argv array is correctly terminated...
authorDave Korn <dave.korn.cygwin@gmail.com>
Wed, 9 Jun 2010 16:46:59 +0000 (16:46 +0000)
committerDave Korn <davek@gcc.gnu.org>
Wed, 9 Jun 2010 16:46:59 +0000 (16:46 +0000)
* opts-common.c (prune_options): Ensure replacement argv array
is correctly terminated by a NULL entry.

From-SVN: r160496

gcc/ChangeLog
gcc/opts-common.c

index bc5886e8a47760aa0fdac4b63355179ab50e7b68..b60675d1b83274bea2208d49297c37d86b18fbd1 100644 (file)
@@ -1,3 +1,8 @@
+2010-06-09  Dave Korn  <dave.korn.cygwin@gmail.com>
+
+       * opts-common.c (prune_options): Ensure replacement argv array
+       is correctly terminated by a NULL entry.
+
 2010-06-09  Jan Hubicka  <jh@suse.cz>
 
        * cgraph.h (varpool_first_static_initializer,
index b70b823db16eb247b7f68704d81dc5ebb81f7b06..d9368d50f14a1a3b012cd78fff7437502c712936 100644 (file)
@@ -132,6 +132,10 @@ prune_options (int *argcp, char ***argvp)
 {
   int argc = *argcp;
   int *options = XNEWVEC (int, argc);
+  /* We will only return this replacement argv if we remove at least
+     one argument, so it does not need to be size (argc + 1) to
+     make room for the terminating NULL because we will always have
+     freed up at least one slot when we end up using it at all.  */
   char **argv = XNEWVEC (char *, argc);
   int i, arg_count, need_prune = 0;
   const struct cl_option *option;
@@ -225,6 +229,9 @@ keep:
     {
       *argcp = arg_count;
       *argvp = argv;
+      /* Add NULL-termination.  Guaranteed not to overflow because
+        arg_count here can only be less than argc.  */
+      argv[arg_count] = 0;
     }
   else
     {