Blame SOURCES/boost-1.58.0-pool.patch

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