Fix max_size to return the size_type(-1)/sizeof(value_type), as otherwise it would overflow on allocation.

This commit is contained in:
Ion Gaztañaga
2015-01-17 22:52:17 +01:00
parent 7635eba375
commit 1012987897
2 changed files with 2 additions and 2 deletions

View File

@@ -339,7 +339,7 @@ struct allocator_traits
{ return a.max_size(); }
static size_type priv_max_size(container_detail::false_type, const Allocator &) BOOST_CONTAINER_NOEXCEPT
{ return size_type(-1); }
{ return size_type(-1)/sizeof(value_type); }
static Allocator priv_select_on_container_copy_construction(container_detail::true_type, const Allocator &a)
{ return a.select_on_container_copy_construction(); }

View File

@@ -322,7 +322,7 @@ int main()
CAllocTraits::max_size(c_alloc);
BOOST_TEST(c_alloc.max_size_called());
SAllocTraits::max_size(s_alloc);
BOOST_TEST(SAllocTraits::size_type(-1)/sizeof(SAllocTraits::value_type) == SAllocTraits::max_size(s_alloc));
//select_on_container_copy_construction
CAllocTraits::select_on_container_copy_construction(c_alloc);