Patchwork [gcov] fix 51297

login
register
mail settings
Submitter Nathan Sidwell
Date Nov. 26, 2011, 9:46 p.m.
Message ID <4ED15E1F.9090903@acm.org>
Download mbox | patch
Permalink /patch/127820/
State New
Headers show

Comments

Nathan Sidwell - Nov. 26, 2011, 9:46 p.m.
I've applied this patch to fix issue 51297.  Solaris' bsearch blows up with a 
NULL array.  I also noticed the possibility of passing NULL pointers to memcpy, 
so took the opportunity of fixing that too.  Thanks to Eric for verifying the 
fix is good.

nathan
2011-11-26  Nathan Sidwell  <nathan@acm.org>

	PR gcov-profile/51297
	* gcov.c (main): Allocate initial names and sources arrays.
	(find_source): Don't check for null name or source arrays here.

Patch

Index: gcov.c
===================================================================
--- gcov.c	(revision 181744)
+++ gcov.c	(working copy)
@@ -406,6 +406,11 @@  main (int argc, char **argv)
   /* Handle response files.  */
   expandargv (&argc, &argv);
 
+  a_names = 10;
+  names = XNEWVEC (name_map_t, a_names);
+  a_sources = 10;
+  sources = XNEWVEC (source_t, a_sources);
+  
   argno = process_args (argc, argv);
   if (optind == argc)
     print_usage (true);
@@ -874,8 +879,6 @@  find_source (const char *file_name)
     {
       /* Extend the name map array -- we'll be inserting one or two
 	 entries.  */
-      if (!a_names)
-	a_names = 10;
       a_names *= 2;
       name_map = XNEWVEC (name_map_t, a_names);
       memcpy (name_map, names, n_names * sizeof (*names));
@@ -894,8 +897,6 @@  find_source (const char *file_name)
       
       if (n_sources == a_sources)
 	{
-	  if (!a_sources)
-	    a_sources = 10;
 	  a_sources *= 2;
 	  src = XNEWVEC (source_t, a_sources);
 	  memcpy (src, sources, n_sources * sizeof (*sources));