incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <se...@roguewave.com>
Subject Re: [patch] STDCXX-170
Date Wed, 18 Jul 2007 00:58:04 GMT
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?

It should also run successfully to completion but in debug
builds it aborts instead. That looks like a bug in our
implementation of the debugging iterators.

#include <iterator>
#include <string>

struct Iterator: std::string::const_reverse_iterator
{
     char operator* () const {
         return std::string::const_reverse_iterator::operator* ();
     }
};

int main ()
{
     std::string s;
     s.replace (s.begin (), s.end (), Iterator (), Iterator ());
}

Martin

> +
> +        // __first2 points to internal string buffer
> +        return __s.replace (__first1, __last1,
> +                            basic_string (__first2, __last2));
> +    }
> +
>       // use a (probably) faster algorithm if possible
>       if
> (_STD::__is_bidirectional_iterator(_RWSTD_ITERATOR_CATEGORY(_InputIter,
>  
> __last2)))
> 
>  
> Farid.
> 


Mime
View raw message