Blame SOURCES/boost-1.58.0-pool.patch

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