Blame SOURCES/boost-1.58.0-pool.patch

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