[PATCH 3/3] Fix tracepoint.c:parse_tracepoint_definition leak (and one more)

Pedro Alves palves@redhat.com
Thu Jan 10 18:08:00 GMT 2019


On 12/14/2018 11:07 PM, Simon Marchi wrote:
> On 2018-12-14 14:12, Pedro Alves wrote:

> I just have one question:
> 
>> diff --git a/gdb/ctf.c b/gdb/ctf.c
>> index ca5266fbd7..e98fb9c1ba 100644
>> --- a/gdb/ctf.c
>> +++ b/gdb/ctf.c
>> @@ -596,38 +596,42 @@ ctf_write_uploaded_tp (struct trace_file_writer *self,
>>
>>    /* condition  */
>>    if (tp->cond != NULL)
>> -    ctf_save_write (&writer->tcs, (gdb_byte *) tp->cond, strlen (tp->cond));
>> +    ctf_save_write (&writer->tcs, (gdb_byte *) tp->cond.get (),
>> +            strlen (tp->cond.get ()));
>>    ctf_save_write (&writer->tcs, &zero, 1);
>>
>>    /* actions */
>>    u32 = tp->actions.size ();
>>    ctf_save_align_write (&writer->tcs, (gdb_byte *) &u32, 4, 4);
>> -  for (char *act : tp->actions)
>> -    ctf_save_write (&writer->tcs, (gdb_byte *) act, strlen (act) + 1);
>> +  for (auto &&act : tp->actions)
>> +    ctf_save_write (&writer->tcs, (gdb_byte *) act.get (),
>> +            strlen (act.get ()) + 1);
> 
> Is there a reason to use "auto &&", instead of let's say "const auto &"?  Since we don't want to modify the unique_ptr...
> 
> I just read:
> 
>   https://blog.petrzemek.net/2016/08/17/auto-type-deduction-in-range-based-for-loops/
>   https://isocpp.org/blog/2012/11/universal-references-in-c11-scott-meyers
> 
> and didn't immediately see why it would be useful in this situation, so I thought I'd ask.

No reason, I had just written auto&& without thinking about
it, mainly because auto&& universally works.

I changed it to 'const auto &' and pushed in the series.

Thanks,
Pedro Alves



More information about the Gdb-patches mailing list