This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH 3/3] Fix tracepoint.c:parse_tracepoint_definition leak (and one more)
- From: Pedro Alves <palves at redhat dot com>
- To: Simon Marchi <simon dot marchi at polymtl dot ca>
- Cc: gdb-patches at sourceware dot org
- Date: Thu, 10 Jan 2019 18:07:58 +0000
- Subject: Re: [PATCH 3/3] Fix tracepoint.c:parse_tracepoint_definition leak (and one more)
- References: <20181214191242.21560-1-palves@redhat.com> <20181214191242.21560-4-palves@redhat.com> <d9c861d242c40ce5b3e4c018a4a26a0b@polymtl.ca>
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