diff options
author | Mike Frysinger <vapier@gentoo.org> | 2021-01-09 00:54:57 -0500 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2021-01-09 08:40:07 -0500 |
commit | b5a4a01af4ef4f5edefacf45dc173f559d09c4b5 (patch) | |
tree | 80103317f1356df7788c3f7fda5bc25cca5ba675 /sim/common | |
parent | be2c78856d6ffe491ae41a7dda58b8553e71dd0f (diff) | |
download | gdb-b5a4a01af4ef4f5edefacf45dc173f559d09c4b5.zip gdb-b5a4a01af4ef4f5edefacf45dc173f559d09c4b5.tar.gz gdb-b5a4a01af4ef4f5edefacf45dc173f559d09c4b5.tar.bz2 |
sim: hw: rework code to avoid gcc warnings
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.
Diffstat (limited to 'sim/common')
-rw-r--r-- | sim/common/ChangeLog | 5 | ||||
-rw-r--r-- | sim/common/hw-base.c | 10 |
2 files changed, 8 insertions, 7 deletions
diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog index 52a2003..28284ff 100644 --- a/sim/common/ChangeLog +++ b/sim/common/ChangeLog @@ -1,5 +1,10 @@ 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. * cgen-trace.c, hw-events.c, sim-abort.c: Likewise. diff --git a/sim/common/hw-base.c b/sim/common/hw-base.c index d4b5198..87ca729 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; } |