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] Add overflow checking to basic_string append and push_back
Date Thu, 20 Sep 2007 22:39:52 GMT
Travis Vitek wrote:
[...]
>> The change also seems unnecessary -- when size() equals capacity()
>> we check that it doesn't exceed max_size() before allocating more
>> memory in append(). Otherwise, when size() is less than capacity()
>> (or rather capacity() - 1), there should be no reason to check
>> against max_size() because we know that capacity() must have
>> been below max_size() the last time we reallocated.
> 
> If that is the case, then why would we possibly need this same code in
> any of the other methods that are used to extend the original string?

I don't think we do, really. I suspect the main reason why the
code is in all other (out-of-line) modifiers is so we can throw
the exception from function that is called directly by program
rather than from the one that happens to be called from it to
do the real work (all roads lead to replace()).

I think the test case has some problems but I just saw your
update so I'll follow up on it there.

Martin

Mime
View raw message