This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]