]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
asan: null pointer as arg 2 of memcpy
authorAlan Modra <amodra@gmail.com>
Thu, 1 May 2025 05:13:46 +0000 (14:43 +0930)
committerAlan Modra <amodra@gmail.com>
Thu, 1 May 2025 13:20:35 +0000 (22:50 +0930)
Replace xmalloc+memcpy+free with xrealloc, avoiding the asan warning
on the initial allocation where we had memcpy(p,0,0).

* cg_arcs.c (arc_add): Use xrealloc.

gprof/cg_arcs.c

index a19686b2710e877330ee23b58c228c10126837fa..9085be08e5e3f14eba4b960283d4952f0cc1750d 100644 (file)
@@ -89,7 +89,7 @@ void
 arc_add (Sym *parent, Sym *child, unsigned long count)
 {
   static unsigned int maxarcs = 0;
-  Arc *arc, **newarcs;
+  Arc *arc;
 
   DBG (TALLYDEBUG, printf ("[arc_add] %lu arcs from %s to %s\n",
                           count, parent->name, child->name));
@@ -124,17 +124,7 @@ arc_add (Sym *parent, Sym *child, unsigned long count)
            maxarcs = 1;
          maxarcs *= 2;
 
-         /* Allocate the new array.  */
-         newarcs = (Arc **)xmalloc(sizeof (Arc *) * maxarcs);
-
-         /* Copy the old array's contents into the new array.  */
-         memcpy (newarcs, arcs, numarcs * sizeof (Arc *));
-
-         /* Free up the old array.  */
-         free (arcs);
-
-         /* And make the new array be the current array.  */
-         arcs = newarcs;
+         arcs = xrealloc (arcs, sizeof (*arcs) * maxarcs);
        }
 
       /* Place this arc in the arc array.  */