[PATCH] sim: hw: rework code to avoid gcc warnings
Mike Frysinger
vapier@gentoo.org
Sat Jan 9 05:57:31 GMT 2021
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/:
* hw-base.c (full_name_of_hw): Delete full_name. Replace
hw_strdup call with hw_malloc.
---
sim/common/hw-base.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/sim/common/hw-base.c b/sim/common/hw-base.c
index d4b519845d1e..87ca7292e558 100644
--- a/sim/common/hw-base.c
+++ b/sim/common/hw-base.c
@@ -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;
}
--
2.28.0
More information about the Gdb-patches
mailing list