gdb: Simplification in charset.c

Message ID 20200220121024.116818-1-ldurfina@tachyum.com
State New
Headers show
Series
  • gdb: Simplification in charset.c
Related show

Commit Message

Lukas Durfina Feb. 20, 2020, 12:10 p.m.
Simplification of the code by using std::string.
Explicit memory allocation and releasing is removed.

gdb/Changelog:
2020-02-20 Lukas Durfina <ldurfina@tachyum.com>

       * charset.c (find_charset_names): Simplify.
---
 gdb/ChangeLog |  4 ++++
 gdb/charset.c | 10 +++-------
 2 files changed, 7 insertions(+), 7 deletions(-)

-- 
2.17.1

Comments

Simon Marchi Feb. 20, 2020, 2:54 p.m. | #1
On 2020-02-20 7:10 a.m., Lukas Durfina wrote:
> @@ -818,13 +818,10 @@ find_charset_names (void)

>    {

>      std::string iconv_dir = relocate_gdb_directory (ICONV_BIN,

>  						    ICONV_BIN_RELOCATABLE);

> -    iconv_program

> -      = concat (iconv_dir.c_str(), SLASH_STRING, "iconv", (char *) NULL);

> +    iconv_program = iconv_dir + SLASH_STRING + "iconv";

>    }

> -#else

> -  iconv_program = xstrdup ("iconv");

>  #endif

> -  args[0] = iconv_program;

> +  args[0] = iconv_program.c_str();


Missing space before parenthesis.

The patch LGTM with that fixed.  Do you have push access, or would you like me to
push the patch on your behalf?

Simon
Lukas Durfina Feb. 20, 2020, 3 p.m. | #2
> -----Original Message-----

> From: Simon Marchi <simark@simark.ca>

> Sent: Thursday, February 20, 2020 3:54 PM

> To: Lukas Durfina <ldurfina@tachyum.com>; gdb-patches@sourceware.org

> Subject: Re: [PATCH] gdb: Simplification in charset.c

> 

> On 2020-02-20 7:10 a.m., Lukas Durfina wrote:

> > @@ -818,13 +818,10 @@ find_charset_names (void)

> >    {

> >      std::string iconv_dir = relocate_gdb_directory (ICONV_BIN,

> >

> ICONV_BIN_RELOCATABLE);

> > -    iconv_program

> > -      = concat (iconv_dir.c_str(), SLASH_STRING, "iconv", (char *) NULL);

> > +    iconv_program = iconv_dir + SLASH_STRING + "iconv";

> >    }

> > -#else

> > -  iconv_program = xstrdup ("iconv");

> >  #endif

> > -  args[0] = iconv_program;

> > +  args[0] = iconv_program.c_str();

> 

> Missing space before parenthesis.

> 

> The patch LGTM with that fixed.  Do you have push access, or would you like

> me to push the patch on your behalf?

> 

> Simon


Ahh, sorry for that missing space.
I do not have push access yet. Push it please.

Thank you

Lukas

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e3f7e9f828..f5de45b992 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,7 @@ 
+2020-02-20 Lukas Durfina <ldurfina@tachyum.com>
+
+	* charset.c (find_charset_names): Simplify.
+
 2020-02-19  Tom Tromey  <tom@tromey.com>
 
 	* symtab.c (general_symbol_info::compute_and_set_names): Use
diff --git a/gdb/charset.c b/gdb/charset.c
index 4e459c2b45..ffdc663f8b 100644
--- a/gdb/charset.c
+++ b/gdb/charset.c
@@ -804,7 +804,7 @@  find_charset_names (void)
   int fail = 1;
   int flags;
   gdb_environ iconv_env = gdb_environ::from_host_environ ();
-  char *iconv_program;
+  std::string iconv_program = "iconv";
 
   /* Older iconvs, e.g. 2.2.2, don't omit the intro text if stdout is
      not a tty.  We need to recognize it and ignore it.  This text is
@@ -818,13 +818,10 @@  find_charset_names (void)
   {
     std::string iconv_dir = relocate_gdb_directory (ICONV_BIN,
 						    ICONV_BIN_RELOCATABLE);
-    iconv_program
-      = concat (iconv_dir.c_str(), SLASH_STRING, "iconv", (char *) NULL);
+    iconv_program = iconv_dir + SLASH_STRING + "iconv";
   }
-#else
-  iconv_program = xstrdup ("iconv");
 #endif
-  args[0] = iconv_program;
+  args[0] = iconv_program.c_str();
   args[1] = "-l";
   args[2] = NULL;
   flags = PEX_STDERR_TO_STDOUT;
@@ -906,7 +903,6 @@  find_charset_names (void)
 
     }
 
-  xfree (iconv_program);
   pex_free (child);
 
   if (fail)