This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix warning on gdb/compile/compile.c (C++-ify "triplet_rx")


On Wednesday, January 17 2018, Simon Marchi wrote:

> On 2018-01-16 14:46, Sergio Durigan Junior wrote:
>> This fixes a GCC warning that happens when compiling
>> gdb/compile/compile.c on some GCC versions (e.g., "gcc (GCC) 7.2.1
>> 20180104 (Red Hat 7.2.1-6)").
>>
>> It's a simple patch that converts "triplet_rx" from "char *" to
>> "std::string", thus guaranteeing that it will be always initialized.
>>
>> I've regtested this patch and did not find any regressions.  OK to
>> apply on both master and 8.1 (after creating a bug for it)?
>>
>> gdb/ChangeLog:
>> 2018-01-16  Sergio Durigan Junior  <sergiodj@redhat.com>
>>
>> 	* compile/compile.c (compile_to_object): Convert "triplet_rx"
>> 	to "std::string".
>> ---
>>  gdb/compile/compile.c | 15 ++++++++-------
>>  1 file changed, 8 insertions(+), 7 deletions(-)
>>
>> diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
>> index 2ee75930ac..47646169c8 100644
>> --- a/gdb/compile/compile.c
>> +++ b/gdb/compile/compile.c
>> @@ -463,7 +463,7 @@ compile_to_object (struct command_line *cmd, const
>> char *cmd_string,
>>    char **argv;
>>    int ok;
>>    struct gdbarch *gdbarch = get_current_arch ();
>> -  char *triplet_rx;
>> +  std::string triplet_rx;
>>    char *error_message;
>>
>>    if (!target_has_execution)
>> @@ -527,15 +527,15 @@ compile_to_object (struct command_line *cmd,
>> const char *cmd_string,
>>      }
>>    else
>>      {
>> -      const char *os_rx = osabi_triplet_regexp (gdbarch_osabi
>> (gdbarch));
>> -      const char *arch_rx = gdbarch_gnu_triplet_regexp (gdbarch);
>> +      std::string os_rx = osabi_triplet_regexp (gdbarch_osabi
>> (gdbarch));
>> +      std::string arch_rx = gdbarch_gnu_triplet_regexp (gdbarch);
>
> Making these std::string makes unnecessary copies.
>
> You can write the line below like this:
>
>   triplet_rx = std::string (arch_rx) + "(-[^-]*)?-" + os_rx;
>
> Otherwise, LGTM.

Thanks, Simon.

Pushed to master:

7d937cad0acdccd0ff485435fbe16f005e994c66

Is it OK to push this to the 8.1 branch as well?  If so, I'm not sure I
should create a bug for this, or just go ahead and push it.

Thanks,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]