Blame SOURCES/boost-1.58.0-pool.patch

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