Remove allocation overflow warnings in some gcc versions in release mode

This commit is contained in:
Ion Gaztañaga
2019-04-30 18:03:40 +02:00
parent 24e420abe9
commit 4c6bea0bc7
3 changed files with 9 additions and 8 deletions
+3 -2
View File
@@ -154,7 +154,8 @@ class new_allocator
//!Throws std::bad_alloc if there is no enough memory
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();
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.
//!Never throws
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
//!because this new_allocator is stateless