Fix for Trac #11412 ("reserve() : null pointer passed to memmove")

This commit is contained in:
Ion Gaztañaga
2015-07-02 13:50:08 +02:00
parent 5d35aec80f
commit a7f60c1e8c
2 changed files with 22 additions and 14 deletions

View File

@@ -175,8 +175,10 @@ inline F memmove(I f, I l, F r) BOOST_NOEXCEPT_OR_NOTHROW
{
typedef typename boost::container::iterator_traits<I>::value_type value_type;
typename boost::container::iterator_traits<I>::difference_type n = boost::container::iterator_distance(f, l);
std::memmove((iterator_to_raw_pointer)(r), (iterator_to_raw_pointer)(f), sizeof(value_type)*n);
boost::container::iterator_advance(r, n);
if(n){
std::memmove((iterator_to_raw_pointer)(r), (iterator_to_raw_pointer)(f), sizeof(value_type)*n);
boost::container::iterator_advance(r, n);
}
return r;
}
@@ -186,8 +188,10 @@ template
F memmove_n(I f, typename boost::container::iterator_traits<I>::difference_type n, F r) BOOST_NOEXCEPT_OR_NOTHROW
{
typedef typename boost::container::iterator_traits<I>::value_type value_type;
std::memmove((iterator_to_raw_pointer)(r), (iterator_to_raw_pointer)(f), sizeof(value_type)*n);
boost::container::iterator_advance(r, n);
if(n){
std::memmove((iterator_to_raw_pointer)(r), (iterator_to_raw_pointer)(f), sizeof(value_type)*n);
boost::container::iterator_advance(r, n);
}
return r;
}
@@ -196,9 +200,11 @@ template
typename F> // F models ForwardIterator
I memmove_n_source(I f, typename boost::container::iterator_traits<I>::difference_type n, F r) BOOST_NOEXCEPT_OR_NOTHROW
{
typedef typename boost::container::iterator_traits<I>::value_type value_type;
std::memmove((iterator_to_raw_pointer)(r), (iterator_to_raw_pointer)(f), sizeof(value_type)*n);
boost::container::iterator_advance(f, n);
if(n){
typedef typename boost::container::iterator_traits<I>::value_type value_type;
std::memmove((iterator_to_raw_pointer)(r), (iterator_to_raw_pointer)(f), sizeof(value_type)*n);
boost::container::iterator_advance(f, n);
}
return f;
}
@@ -208,9 +214,11 @@ template
I memmove_n_source_dest(I f, typename boost::container::iterator_traits<I>::difference_type n, F &r) BOOST_NOEXCEPT_OR_NOTHROW
{
typedef typename boost::container::iterator_traits<I>::value_type value_type;
std::memmove((iterator_to_raw_pointer)(r), (iterator_to_raw_pointer)(f), sizeof(value_type)*n);
boost::container::iterator_advance(f, n);
boost::container::iterator_advance(r, n);
if(n){
std::memmove((iterator_to_raw_pointer)(r), (iterator_to_raw_pointer)(f), sizeof(value_type)*n);
boost::container::iterator_advance(f, n);
boost::container::iterator_advance(r, n);
}
return f;
}

View File

@@ -60,7 +60,7 @@ class small_vector_base;
//! for documentation purposes.
//!
//! This allocator inherits from a standard-conforming allocator
//! and forwards member functiond to the standard allocator except
//! and forwards member functions to the standard allocator except
//! when internal storage is being used as memory source.
//!
//! This allocator is a "partially_propagable" allocator and
@@ -68,7 +68,7 @@ class small_vector_base;
//!
//! A partially propagable allocator means that not all storage
//! allocatod by an instance of `small_vector_allocator` can be
//! deallocated by another instance of this type, even is both
//! deallocated by another instance of this type, even if both
//! instances compare equal or an instance is propagated to another
//! one using the copy/move constructor or assignment. The storage that
//! can never be propagated is identified by `storage_is_unpropagable(p)`.
@@ -432,8 +432,8 @@ struct small_vector_storage_definer
#endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
//! small_vector a vector-like container optimized for the case when it contains few elements.
//! It contains some preallocated elements in-place, which allows it to avoid the use of dynamic storage allocation
//! small_vector is a vector-like container optimized for the case when it contains few elements.
//! It contains some preallocated elements in-place, which can avoid the use of dynamic storage allocation
//! when the actual number of elements is below that preallocated threshold.
//!
//! `small_vector<T, N, Allocator>` is convertible to `small_vector_base<T, Allocator>` that is independent