This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] libstdc++/8466


Jonathan Wakely wrote:

Could this be done safely if basic_stringbuf could tell the Rep it was
being modified, so a copy would be made when the buffer is directly
modified?
If basic_stringbuf can modify the Rep directly, shouldn't it do so safely,
rather than trying to ensure that the string it modifies is never shared?
Otherwise similar bugs could be introduced in future if someone is unaware
that basic_stringbuf modifies the buffer directly.

In principle, I agree. However, this is a *much* more invasive change which I would rather
prefer considering in a second pass through this code... Anyway, patches welcome!

I have fixed this with a "low-level assignment" of __s
to _M_string:

void
str(const __string_type& __s)
{ _M_string.assign(__s.c_str(), __s.size());

Could this be

       _M_string.assign(__s.data(), __s.size());

to avoid assigning the unnecessary NULL-terminator?

Yes, you are right. I'm going to commit (after testing) this slight improvement. Thanks!

Ciao, Paolo.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]