diff --git a/test/default_init_test.hpp b/test/default_init_test.hpp index 2e83a36..7d6bedc 100644 --- a/test/default_init_test.hpp +++ b/test/default_init_test.hpp @@ -12,8 +12,10 @@ #define BOOST_CONTAINER_TEST_DEFAULT_INIT_TEST_HEADER #include +#include #include + namespace boost{ namespace container { namespace test{ @@ -57,6 +59,10 @@ class default_init_allocator Integral* allocate(std::size_t n) { + const std::size_t max_count = std::size_t(-1)/(2*sizeof(Integral)); + if(BOOST_UNLIKELY(n > max_count)) + throw_bad_alloc(); + //Initialize memory to a pattern const std::size_t max = sizeof(Integral)*n; unsigned char *puc_raw = ::new unsigned char[max];