From: Jonathan Wakely <jwakely@redhat.com>
To: Tim Shen <timshen@google.com>
Cc: libstdc++ <libstdc++@gcc.gnu.org>, gcc-patches@gcc.gnu.org
Subject: Re: [Patch, libstdc++/63497] Avoid dereferencing invalid iterator in regex_executor
Date: Wed, 22 Oct 2014 14:39:00 -0000 [thread overview]
Message-ID: <20141022143426.GR3033@redhat.com> (raw)
In-Reply-To: <CAG4ZjNke_2USeng2gpkSq7TJn7MQjcRuQX_CscZcd0KFQqqESg@mail.gmail.com>
On 21/10/14 09:45 -0700, Tim Shen wrote:
>On Tue, Oct 21, 2014 at 3:25 AM, Jonathan Wakely <jwakely@redhat.com> wrote:
>> Did you manage to produce a testcase that crashed on trunk?
>
>Oh I forgot to mention that I've tried my best to make a testcase that
>crash the trunk, but failed :).
>
>I'm not sure if I should directly put an assert in the code and make a
>testcase to explode it. Now I think it's better to do it.
Only if it's likely to catch problems in future. If you'd be putting
it in only to make a testcase fail then it's not worth it.
>> Is it really necessary to modify _M_current here?
>> Couldn't you do:
>>
>> auto __pre = _M_current;
>> if (_M_is_word(*--__pre))
>> __left_is_word = true;
>>
>> Then the function could remain const, couldn't it?
>
>That's exactly what I did in the early version of this patch. But
>later I changed because I assume that copying an iterator is
>potentially expensive, but mutating is cheaper.
In general iterators are always passed by value and should be cheap to
copy. Inside regex the iterator is usually a const char* so is very
cheap to copy.
>Making this function const may bring some optimization, doesn't it?
>But I have no idea how much it will bring and if it's worthy.
It's unlikely (see http://www.gotw.ca/gotw/081.htm).
I just don't see the point in making it a non-const function just to
perform a micro-optimisation.
If you were passing an integer to a function would you do
f(i-1);
or
--i;
f(i);
++i;
?
The first form seems obviously better to me.
You could even simplify it further using std::prev:
if (_M_is_word(*std::prev(__pre)))
__left_is_word = true;
next prev parent reply other threads:[~2014-10-22 14:34 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-20 17:28 Tim Shen
2014-10-21 10:54 ` Jonathan Wakely
2014-10-21 16:48 ` Tim Shen
2014-10-22 14:39 ` Jonathan Wakely [this message]
2014-10-22 22:04 ` Tim Shen
2014-10-22 23:05 ` Jonathan Wakely
2014-10-23 3:29 ` Tim Shen
2014-11-25 8:46 ` Tim Shen
2014-11-25 11:11 ` Jonathan Wakely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20141022143426.GR3033@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
--cc=timshen@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).