incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Farid Zaripov" <Farid_Zari...@epam.com>
Subject RE: [patch] STDCXX-170
Date Thu, 19 Jul 2007 16:19:00 GMT
> -----Original Message-----
> From: Martin Sebor [mailto:msebor@gmail.com] On Behalf Of Martin Sebor
> Sent: Wednesday, July 18, 2007 3:58 AM
> To: stdcxx-dev@incubator.apache.org
> Subject: Re: [patch] STDCXX-170
> 
> Farid Zaripov wrote:
> >   Here is proposed patch to fix STDCXX-170 issue:
> >  
> >   ChangeLog:
> >   * string.cc (replace): Copy data to temporary string object
> >   if data is a part of the internal string buffer.
> >  
> > Index: string.cc
> > ===================================================================
> > --- string.cc (revision 556830)
> > +++ string.cc (working copy)
> > @@ -516,6 +516,15 @@
> >      _RWSTD_ASSERT_RANGE (__first1, __last1);
> >      _RWSTD_ASSERT_RANGE (__first2, __last2);
> >  
> > +    if (   !(__first2 == __last2)
> > +        && __s._C_data <= &*__first2
> > +        && __s._C_data + __s.size () > &*__first2) {
> 
> I don't think this exression is guaranteed to be well-formed.
> InputIterator's operator* can return an rvalue (rather than
> a const reference) which would break operator &. The test
> case below should compile. Does it with your change?

  You're right. This test case fails to compile with my patch.
I looked into STLport sources to see how it deals with that problem.
The STLport performs checking only if InputIter is
basic_string::iterator
or basic_string::const_iterator:

  template <class _InputIter>
  void _M_insert_dispatch(iterator __p, _InputIter __first, _InputIter
__last,
                          const __false_type& /*Integral*/) {
    _STLP_FIX_LITERAL_BUG(__p)
    /*
     * Within the basic_string implementation we are only going to check
for
     * self referencing if iterators are string iterators or _CharT
pointers.
     * A user could encapsulate those iterator within their own iterator
interface
     * and in this case lead to a bad behavior, this is a known
limitation.
     */
    typedef typename _AreSameUnCVTypes<_InputIter, iterator>::_Ret
_IsIterator;
    typedef typename _AreSameUnCVTypes<_InputIter, const_iterator>::_Ret
_IsConstIterator;
    typedef typename _Lor2<_IsIterator, _IsConstIterator>::_Ret
_CheckInside;
    _M_insert_aux(__p, __first, __last, _CheckInside());
  }

Farid.

Mime
View raw message