sim: hw: rework code to avoid gcc warnings
authorMike Frysinger <vapier@gentoo.org>
Sat, 9 Jan 2021 05:54:57 +0000 (00:54 -0500)
committerMike Frysinger <vapier@gentoo.org>
Sat, 9 Jan 2021 13:40:07 +0000 (08:40 -0500)
Newer gcc thinks we might return a pointer to a stack buffer, but
we don't -- we strdup it before returning.  Rework the code to just
malloc the buffer from the start and avoid the stack+strdup.

sim/common/ChangeLog
sim/common/hw-base.c

index 52a2003e9c61a54aea03354043e158fcf5c1dcb8..28284ff844423f566c969268340f68cd3fc48a4e 100644 (file)
@@ -1,3 +1,8 @@
+2021-01-09  Mike Frysinger  <vapier@gentoo.org>
+
+       * hw-base.c (full_name_of_hw): Delete full_name.  Replace
+       hw_strdup call with hw_malloc.
+
 2021-01-09  Mike Frysinger  <vapier@gentoo.org>
 
        * cgen-par.c: Include stdlib.h.
index d4b519845d1e7354914623f375dbd2dba9e47426..87ca7292e55808403eb9e8eb582a80d3d63bd928 100644 (file)
@@ -281,11 +281,10 @@ full_name_of_hw (struct hw *leaf,
                 unsigned sizeof_buf)
 {
   /* get a buffer */
-  char full_name[1024];
-  if (buf == (char*)0)
+  if (buf == NULL)
     {
-      buf = full_name;
-      sizeof_buf = sizeof (full_name);
+      sizeof_buf = 1024;
+      buf = hw_malloc (leaf, sizeof_buf);
     }
 
   /* use head recursion to construct the path */
@@ -318,9 +317,6 @@ full_name_of_hw (struct hw *leaf,
       strcat (buf, unit);
     }
 
-  /* return it usefully */
-  if (buf == full_name)
-    buf = hw_strdup (leaf, full_name);
   return buf;
 }