Blame SOURCES/boost-1.58.0-pool.patch

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