Blame SOURCES/boost-1.58.0-pool.patch

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