Blame SOURCES/boost-1.58.0-pool.patch

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