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