mirror of
https://github.com/boostorg/container.git
synced 2025-08-02 22:14:26 +02:00
Remove allocation overflow warnings in some gcc versions in release mode
This commit is contained in:
@@ -146,13 +146,13 @@ class adaptive_pool
|
|||||||
//!Returns the number of elements that could be allocated.
|
//!Returns the number of elements that could be allocated.
|
||||||
//!Never throws
|
//!Never throws
|
||||||
size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW
|
size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW
|
||||||
{ return size_type(-1)/sizeof(T); }
|
{ return size_type(-1)/(2u*sizeof(T)); }
|
||||||
|
|
||||||
//!Allocate memory for an array of count elements.
|
//!Allocate memory for an array of count elements.
|
||||||
//!Throws std::bad_alloc if there is no enough memory
|
//!Throws std::bad_alloc if there is no enough memory
|
||||||
pointer allocate(size_type count, const void * = 0)
|
pointer allocate(size_type count, const void * = 0)
|
||||||
{
|
{
|
||||||
if(BOOST_UNLIKELY(count > this->max_size()))
|
if(BOOST_UNLIKELY(count > size_type(-1)/(2u*sizeof(T))))
|
||||||
boost::container::throw_bad_alloc();
|
boost::container::throw_bad_alloc();
|
||||||
|
|
||||||
if(Version == 1 && count == 1){
|
if(Version == 1 && count == 1){
|
||||||
@@ -456,13 +456,13 @@ class private_adaptive_pool
|
|||||||
//!Returns the number of elements that could be allocated.
|
//!Returns the number of elements that could be allocated.
|
||||||
//!Never throws
|
//!Never throws
|
||||||
size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW
|
size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW
|
||||||
{ return size_type(-1)/sizeof(T); }
|
{ return size_type(-1)/(2u*sizeof(T)); }
|
||||||
|
|
||||||
//!Allocate memory for an array of count elements.
|
//!Allocate memory for an array of count elements.
|
||||||
//!Throws std::bad_alloc if there is no enough memory
|
//!Throws std::bad_alloc if there is no enough memory
|
||||||
pointer allocate(size_type count, const void * = 0)
|
pointer allocate(size_type count, const void * = 0)
|
||||||
{
|
{
|
||||||
if(BOOST_UNLIKELY(count > this->max_size()))
|
if(BOOST_UNLIKELY(count > size_type(-1)/(2u*sizeof(T))))
|
||||||
boost::container::throw_bad_alloc();
|
boost::container::throw_bad_alloc();
|
||||||
|
|
||||||
if(Version == 1 && count == 1){
|
if(Version == 1 && count == 1){
|
||||||
|
@@ -180,7 +180,7 @@ class allocator
|
|||||||
pointer allocate(size_type count, const void * hint= 0)
|
pointer allocate(size_type count, const void * hint= 0)
|
||||||
{
|
{
|
||||||
(void)hint;
|
(void)hint;
|
||||||
if(count > this->max_size())
|
if(count > size_type(-1)/(2u*sizeof(T)))
|
||||||
boost::container::throw_bad_alloc();
|
boost::container::throw_bad_alloc();
|
||||||
void *ret = dlmalloc_malloc(count*sizeof(T));
|
void *ret = dlmalloc_malloc(count*sizeof(T));
|
||||||
if(!ret)
|
if(!ret)
|
||||||
@@ -196,7 +196,7 @@ class allocator
|
|||||||
//!Returns the maximum number of elements that could be allocated.
|
//!Returns the maximum number of elements that could be allocated.
|
||||||
//!Never throws
|
//!Never throws
|
||||||
BOOST_CONTAINER_FORCEINLINE size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW
|
BOOST_CONTAINER_FORCEINLINE size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW
|
||||||
{ return size_type(-1)/sizeof(T); }
|
{ return size_type(-1)/(2u*sizeof(T)); }
|
||||||
|
|
||||||
//!Swaps two allocators, does nothing
|
//!Swaps two allocators, does nothing
|
||||||
//!because this allocator is stateless
|
//!because this allocator is stateless
|
||||||
|
@@ -154,7 +154,8 @@ class new_allocator
|
|||||||
//!Throws std::bad_alloc if there is no enough memory
|
//!Throws std::bad_alloc if there is no enough memory
|
||||||
pointer allocate(size_type count)
|
pointer allocate(size_type count)
|
||||||
{
|
{
|
||||||
if(BOOST_UNLIKELY(count > this->max_size()))
|
const std::size_t max_count = std::size_t(-1)/(2*sizeof(T));
|
||||||
|
if(BOOST_UNLIKELY(count > max_count))
|
||||||
throw_bad_alloc();
|
throw_bad_alloc();
|
||||||
return static_cast<T*>(::operator new(count*sizeof(T)));
|
return static_cast<T*>(::operator new(count*sizeof(T)));
|
||||||
}
|
}
|
||||||
@@ -167,7 +168,7 @@ class new_allocator
|
|||||||
//!Returns the maximum number of elements that could be allocated.
|
//!Returns the maximum number of elements that could be allocated.
|
||||||
//!Never throws
|
//!Never throws
|
||||||
size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW
|
size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW
|
||||||
{ return size_type(-1)/sizeof(T); }
|
{ return std::size_t(-1)/(2*sizeof(T)); }
|
||||||
|
|
||||||
//!Swaps two allocators, does nothing
|
//!Swaps two allocators, does nothing
|
||||||
//!because this new_allocator is stateless
|
//!because this new_allocator is stateless
|
||||||
|
Reference in New Issue
Block a user