c7fd47
Index: boost/pool/pool.hpp
c7fd47
===================================================================
c7fd47
--- boost/pool/pool.hpp	(revision 78317)
c7fd47
+++ boost/pool/pool.hpp	(revision 78326)
c7fd47
@@ -27,4 +27,6 @@
c7fd47
 #include <boost/pool/poolfwd.hpp>
c7fd47
 
c7fd47
+// std::numeric_limits
c7fd47
+#include <boost/limits.hpp>
c7fd47
 // boost::integer::static_lcm
c7fd47
 #include <boost/integer/common_factor_ct.hpp>
c7fd47
@@ -358,4 +360,11 @@
c7fd47
     }
c7fd47
 
c7fd47
+    size_type max_chunks() const
c7fd47
+    { //! Calculated maximum number of memory chunks that can be allocated in a single call by this Pool.
c7fd47
+      size_type partition_size = alloc_size();
c7fd47
+      size_type POD_size = integer::static_lcm<sizeof(size_type), sizeof(void *)>::value + sizeof(size_type);
c7fd47
+      return (std::numeric_limits<size_type>::max() - POD_size) / alloc_size();
c7fd47
+    }
c7fd47
+
c7fd47
     static void * & nextof(void * const ptr)
c7fd47
     { //! \returns Pointer dereferenced.
c7fd47
@@ -377,5 +388,7 @@
c7fd47
       //!   the first time that object needs to allocate system memory.
c7fd47
       //!   The default is 32. This parameter may not be 0.
c7fd47
-      //! \param nmax_size is the maximum number of chunks to allocate in one block.
c7fd47
+      //! \param nmax_size is the maximum number of chunks to allocate in one block.			
c7fd47
+      set_next_size(nnext_size);
c7fd47
+      set_max_size(nmax_size);
c7fd47
     }
c7fd47
 
c7fd47
@@ -400,7 +413,7 @@
c7fd47
     }
c7fd47
     void set_next_size(const size_type nnext_size)
c7fd47
-    { //! Set number of chunks to request from the system the next time that object needs to allocate system memory. This value should never be set to 0.
c7fd47
-      //! \returns nnext_size.
c7fd47
-      next_size = start_size = nnext_size;
c7fd47
+    { //! Set number of chunks to request from the system the next time that object needs to allocate system memory. This value should never be set to 0.     
c7fd47
+      BOOST_USING_STD_MIN();
c7fd47
+      next_size = start_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(nnext_size, max_chunks());
c7fd47
     }
c7fd47
     size_type get_max_size() const
c7fd47
@@ -410,5 +423,6 @@
c7fd47
     void set_max_size(const size_type nmax_size)
c7fd47
     { //! Set max_size.
c7fd47
-      max_size = nmax_size;
c7fd47
+      BOOST_USING_STD_MIN();
c7fd47
+      max_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(nmax_size, max_chunks());
c7fd47
     }
c7fd47
     size_type get_requested_size() const
c7fd47
@@ -713,7 +727,7 @@
c7fd47
   BOOST_USING_STD_MIN();
c7fd47
   if(!max_size)
c7fd47
-    next_size <<= 1;
c7fd47
+    set_next_size(next_size << 1);
c7fd47
   else if( next_size*partition_size/requested_size < max_size)
c7fd47
-    next_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size*requested_size/ partition_size);
c7fd47
+    set_next_size(min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size * requested_size / partition_size));
c7fd47
 
c7fd47
   //  initialize it,
c7fd47
@@ -753,7 +767,7 @@
c7fd47
   BOOST_USING_STD_MIN();
c7fd47
   if(!max_size)
c7fd47
-    next_size <<= 1;
c7fd47
+    set_next_size(next_size << 1);
c7fd47
   else if( next_size*partition_size/requested_size < max_size)
c7fd47
-    next_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size*requested_size/ partition_size);
c7fd47
+    set_next_size(min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size * requested_size / partition_size));
c7fd47
 
c7fd47
   //  initialize it,
c7fd47
@@ -797,4 +811,6 @@
c7fd47
   //! \returns Address of chunk n if allocated ok.
c7fd47
   //! \returns 0 if not enough memory for n chunks.
c7fd47
+  if (n > max_chunks())
c7fd47
+    return 0;
c7fd47
 
c7fd47
   const size_type partition_size = alloc_size();
c7fd47
@@ -845,7 +861,7 @@
c7fd47
   BOOST_USING_STD_MIN();
c7fd47
   if(!max_size)
c7fd47
-    next_size <<= 1;
c7fd47
+    set_next_size(next_size << 1);
c7fd47
   else if( next_size*partition_size/requested_size < max_size)
c7fd47
-    next_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size*requested_size/ partition_size);
c7fd47
+    set_next_size(min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size * requested_size / partition_size));
c7fd47
 
c7fd47
   //  insert it into the list,
c7fd47
Index: libs/pool/test/test_bug_6701.cpp
c7fd47
===================================================================
c7fd47
--- libs/pool/test/test_bug_6701.cpp	(revision 78326)
c7fd47
+++ libs/pool/test/test_bug_6701.cpp	(revision 78326)
c7fd47
@@ -0,0 +1,27 @@
c7fd47
+/* Copyright (C) 2012 Étienne Dupuis
c7fd47
+* 
c7fd47
+* Use, modification and distribution is subject to the 
c7fd47
+* Boost Software License, Version 1.0. (See accompanying
c7fd47
+* file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
c7fd47
+*/
c7fd47
+
c7fd47
+// Test of bug #6701 (https://svn.boost.org/trac/boost/ticket/6701)
c7fd47
+
c7fd47
+#include <boost/pool/object_pool.hpp>
c7fd47
+#include <boost/limits.hpp>
c7fd47
+
c7fd47
+int main()
c7fd47
+{
c7fd47
+  boost::pool<> p(1024, std::numeric_limits<size_t>::max() / 768);
c7fd47
+
c7fd47
+  void *x = p.malloc();
c7fd47
+  BOOST_ASSERT(!x);
c7fd47
+  
c7fd47
+  BOOST_ASSERT(std::numeric_limits<size_t>::max() / 1024 >= p.get_next_size());
c7fd47
+  BOOST_ASSERT(std::numeric_limits<size_t>::max() / 1024 >= p.get_max_size());
c7fd47
+
c7fd47
+  void *y = p.ordered_malloc(std::numeric_limits<size_t>::max() / 768);
c7fd47
+  BOOST_ASSERT(!y);
c7fd47
+
c7fd47
+  return 0;
c7fd47
+}