stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <>
Subject Re: [PATCH] Add overflow checking to basic_string append and push_back
Date Thu, 20 Sep 2007 23:26:34 GMT
Travis Vitek wrote:
> Martin Sebor wrote:
>> Travis Vitek wrote:
>>> 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()).
> The problem I see is this...
>     // if you do this calculation without checking for overflow
>     // you may be surprised when __size becomes smaller than
>     // capacity. [240 + 20 = 6]

I agree that this is at least a theoretical problem (I can't
quite imagine a practical use case for size_type being only
8 bits wide). It might be an interesting exercise to change
string (and the other containers) to work correctly even
with size_type this small so long as it doesn't pessimize
the common case in any way (i.e., I wouldn't be in favor
of introducing a whole bunch of layers of template
metaprogramming tricks to get this to work).

But back to your patch, unless it actually addresses this
problem, we still need a test case for the problem that it
does attempt to fix.


View raw message