From 1012987897517358b259ef8a9412eac01a920076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Sat, 17 Jan 2015 22:52:17 +0100 Subject: [PATCH] Fix max_size to return the size_type(-1)/sizeof(value_type), as otherwise it would overflow on allocation. --- include/boost/container/allocator_traits.hpp | 2 +- test/allocator_traits_test.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/container/allocator_traits.hpp b/include/boost/container/allocator_traits.hpp index a83ecbf..01be0ef 100644 --- a/include/boost/container/allocator_traits.hpp +++ b/include/boost/container/allocator_traits.hpp @@ -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(); } diff --git a/test/allocator_traits_test.cpp b/test/allocator_traits_test.cpp index 7da3ee7..47a3764 100644 --- a/test/allocator_traits_test.cpp +++ b/test/allocator_traits_test.cpp @@ -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);