[RFA] Adding n <= max_size check in allocator::allocate
Paolo Carlini
pcarlini@suse.de
Wed Oct 20 00:13:00 GMT 2004
Hi,
consider this:
std::vector<int> v(size_t(-1) / sizeof(int) + 1, 1);
currently, instead of throwing (bad_alloc), seg faults.
Usual story: in mt_allocator there are no checks for overflows
when n * sizeof(value_type) is computed to call ::operator new,
and the latter happily allocates only *zero* bytes...
Of course this does *not* happen with pool_allocator::allocate
that wraps everything in:
if (__n)
{
if (__n <= this->max_size())
{
...
}
else
__throw_bad_alloc();
}
From a QoI point of view, at least, I think we should have these
checks in our allocators (only pool_allocator is ok!) and mean to
work on this ASAP, together with the corresponding testcases.
Paolo.
More information about the Libstdc++
mailing list