Patchwork [v2] xtensa: Properly strdup string when building reggroup

login
register
mail settings
Submitter Stafford Horne
Date June 13, 2017, 10:36 a.m.
Message ID <20170613103636.24381-1-shorne@gmail.com>
Download mbox | patch
Permalink /patch/20983/
State New
Headers show

Comments

Stafford Horne - June 13, 2017, 10:36 a.m.
I noticed this while looking at the reggroup intializations.  It seems
for xtensa the "cpN" reggroup->name is getting assigned to the same text
pointer for each iteration of XTENSA_MAX_COPROCESSOR.

Note 1, internally reggroup_new() does not do any xstrdup().

Note 2, I could not test this.

gdb/ChangeLog:

2017-06-10  Stafford Horne  <shorne@gmail.com>

	* xtensa-tdep.c (xtensa_init_reggroups): Use xstrdup for cpname.
---
Changes since v1
  * Instead of using 'smart' `'0' + i` formating just use xstrprintf
  * Formatting suggested by Yao

 gdb/xtensa-tdep.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
Yao Qi - June 13, 2017, 1:01 p.m.
Stafford Horne <shorne@gmail.com> writes:

> 2017-06-10  Stafford Horne  <shorne@gmail.com>
>
> 	* xtensa-tdep.c (xtensa_init_reggroups): Use xstrdup for cpname.

Patch is good to me.
Stafford Horne - Aug. 10, 2017, 1:41 p.m.
On Tue, Jun 13, 2017 at 02:01:35PM +0100, Yao Qi wrote:
> Stafford Horne <shorne@gmail.com> writes:
> 
> > 2017-06-10  Stafford Horne  <shorne@gmail.com>
> >
> > 	* xtensa-tdep.c (xtensa_init_reggroups): Use xstrdup for cpname.
> 
> Patch is good to me.

Thanks for the review,

Sorry, I haven't been having time to follow up on my gdb patches lately.
But I will get around to them.

How will this patch get applied?  I am not a maintainer yet.

-Stafford
Yao Qi - Aug. 10, 2017, 9:03 p.m.
On Thu, Aug 10, 2017 at 2:41 PM, Stafford Horne <shorne@gmail.com> wrote:
>
> How will this patch get applied?  I am not a maintainer yet.

Did you get your sourceware.org account?  I think
you got it.  You can clone read-write git, described
in https://sourceware.org/gdb/current/

Patch

diff --git a/gdb/xtensa-tdep.c b/gdb/xtensa-tdep.c
index f9e8584..e9e88b9 100644
--- a/gdb/xtensa-tdep.c
+++ b/gdb/xtensa-tdep.c
@@ -737,17 +737,13 @@  static void
 xtensa_init_reggroups (void)
 {
   int i;
-  char cpname[] = "cp0";
 
   xtensa_ar_reggroup = reggroup_new ("ar", USER_REGGROUP);
   xtensa_user_reggroup = reggroup_new ("user", USER_REGGROUP);
   xtensa_vectra_reggroup = reggroup_new ("vectra", USER_REGGROUP);
 
   for (i = 0; i < XTENSA_MAX_COPROCESSOR; i++)
-    {
-      cpname[2] = '0' + i;
-      xtensa_cp[i] = reggroup_new (cpname, USER_REGGROUP);
-    }
+    xtensa_cp[i] = reggroup_new (xstrprintf ("cp%d", i), USER_REGGROUP);
 }
 
 static void