[cxx-abi-dev] Run-time array checking

Mike Herrick mjh at edg.com
Thu Sep 13 12:57:14 UTC 2012


On Sep 12, 2012, at 11:32 PM, Dennis Handly wrote:

>> From: Mike Herrick <mjh at edg.com>
>> On Sep 11, 2012, at 8:44 PM, John McCall wrote:
>>> On Sep 11, 2012, at 12:28 PM, Mike Herrick wrote:
>>> I hadn't thought of the wider-than-size_t problem, although amusingly I did
>>> remember that case when writing the bounds checks in clang.
>>> 
>>> At the risk of prescribing an overly complicated API, I would suggest:
>>> void __cxa_throw_bad_array_new_length(uintptr_t sizeData, int flags);
>>> where 'flags' is:
>>> (sizeof(size) << 1) | std::is_signed<decltype(size)>::value
>>> and where sizeData is either:
>>> size, converted to a uintptr_t, if sizeof(size) <= sizeof(uintptr_t), or
>>> &size otherwise (throwing it in some temporary memory).
>>> Converting to a uintptr_t means zero-extending or sign-extending as appropriate.
> 
>> Any other opinions on whether we should try to save this value (and if
>> so, in which manner)?
> Mike.
> 
> Wouldn't using a double be good enough?

Unfortunately, I don't think so.  There are several problems with using double: it's not available on every platform, it doesn't handle the case where the sizeof(size) > sizeof(double), and even in cases where sizeof(double) >= sizeof(size), it can only represent integer values that fit in 53 bits.

Mike.



More information about the cxx-abi-dev mailing list