This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[RFA] Adding n <= max_size check in allocator::allocate
- From: Paolo Carlini <pcarlini at suse dot de>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Wed, 20 Oct 2004 02:14:19 +0200
- Subject: [RFA] Adding n <= max_size check in allocator::allocate
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.