[binutils-gdb] asan: null pointer as arg 2 of memcpy
Alan Modra
amodra@sourceware.org
Thu May 1 13:20:55 GMT 2025
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a388feed3d4662623749a2e991ea802000cf74b7
commit a388feed3d4662623749a2e991ea802000cf74b7
Author: Alan Modra <amodra@gmail.com>
Date: Thu May 1 14:43:46 2025 +0930
asan: null pointer as arg 2 of memcpy
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.
Diff:
---
gprof/cg_arcs.c | 14 ++------------
1 file changed, 2 insertions(+), 12 deletions(-)
diff --git a/gprof/cg_arcs.c b/gprof/cg_arcs.c
index a19686b2710..9085be08e5e 100644
--- a/gprof/cg_arcs.c
+++ b/gprof/cg_arcs.c
@@ -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. */
More information about the Binutils-cvs
mailing list