From a063e891bd88967d9dcea0f8c163f8372116265f Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Thu, 21 Oct 2004 00:06:02 +0000 Subject: bitmap_allocator.h (allocate): Throw std::bad_alloc when n > max_size(). 2004-10-20 Paolo Carlini * include/ext/bitmap_allocator.h (allocate): Throw std::bad_alloc when n > max_size(). * include/ext/malloc_allocator.h (allocate): Likewise. * include/ext/mt_allocator.h (allocate): Likewise. * include/ext/new_allocator.h (allocate): Likewise. * include/ext/array_allocator.h: Use __throw_bad_alloc(). * include/ext/pool_allocator.h: Use __builtin_expect. * testsuite/ext/array_allocator/check_allocate_max_size.cc: New. * testsuite/ext/bitmap_allocator/check_allocate_max_size.cc: Likewise. * testsuite/ext/malloc_allocator/check_allocate_max_size.cc: Likewise. * testsuite/ext/mt_allocator/check_allocate_max_size.cc: Likewise. * testsuite/ext/new_allocator/check_allocate_max_size.cc: Likewise. * testsuite/ext/pool_allocator/check_allocate_max_size.cc: Likewise. * testsuite/testsuite_allocator.h (check_allocate_max_size): New test. From-SVN: r89351 --- libstdc++-v3/include/ext/mt_allocator.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'libstdc++-v3/include/ext/mt_allocator.h') diff --git a/libstdc++-v3/include/ext/mt_allocator.h b/libstdc++-v3/include/ext/mt_allocator.h index 5e587ad..6649111 100644 --- a/libstdc++-v3/include/ext/mt_allocator.h +++ b/libstdc++-v3/include/ext/mt_allocator.h @@ -685,6 +685,9 @@ namespace __gnu_cxx { this->_S_initialize_once(); + if (__builtin_expect(__n > this->max_size(), false)) + std::__throw_bad_alloc(); + // Requests larger than _M_max_bytes are handled by operator // new/delete directly. __pool_type& __pool = this->_S_get_pool(); @@ -694,7 +697,7 @@ namespace __gnu_cxx void* __ret = ::operator new(__bytes); return static_cast<_Tp*>(__ret); } - + // Round up to power of 2 and figure out which bin to use. const size_t __which = __pool._M_get_binmap(__bytes); const size_t __thread_id = __pool._M_get_thread_id(); -- cgit v1.1