mirror of
https://github.com/boostorg/container.git
synced 2025-08-02 14:04:26 +02:00
Avoid GCC's overflow warnings for operator new.
This commit is contained in:
@@ -12,8 +12,10 @@
|
|||||||
#define BOOST_CONTAINER_TEST_DEFAULT_INIT_TEST_HEADER
|
#define BOOST_CONTAINER_TEST_DEFAULT_INIT_TEST_HEADER
|
||||||
|
|
||||||
#include <boost/container/detail/config_begin.hpp>
|
#include <boost/container/detail/config_begin.hpp>
|
||||||
|
#include <boost/container/throw_exception.hpp>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
|
|
||||||
namespace boost{
|
namespace boost{
|
||||||
namespace container {
|
namespace container {
|
||||||
namespace test{
|
namespace test{
|
||||||
@@ -57,6 +59,10 @@ class default_init_allocator
|
|||||||
|
|
||||||
Integral* allocate(std::size_t n)
|
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
|
//Initialize memory to a pattern
|
||||||
const std::size_t max = sizeof(Integral)*n;
|
const std::size_t max = sizeof(Integral)*n;
|
||||||
unsigned char *puc_raw = ::new unsigned char[max];
|
unsigned char *puc_raw = ::new unsigned char[max];
|
||||||
|
Reference in New Issue
Block a user