From 8a2444201ac4856e77b46220cb91beb8e8b3c34d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Tue, 3 Nov 2020 10:59:19 +0100 Subject: [PATCH] Avoid GCC's overflow warnings for operator new. --- test/default_init_test.hpp | 6 ++++++ 1 file changed, 6 insertions(+) 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];