Fixed #142 ("memset called with null pointer")

This commit is contained in:
Ion Gaztañaga
2020-02-14 05:10:29 +01:00
parent 04a91b5e54
commit 756c4cdc6a
2 changed files with 9 additions and 4 deletions

View File

@@ -1324,6 +1324,7 @@ use [*Boost.Container]? There are several reasons for that:
* Fixed bugs:
* [@https://github.com/boostorg/container/pull/135 GitHub #135: ['"Missing BOOST_NORETURN for user defined functions"]].
* [@https://github.com/boostorg/container/pull/138 GitHub #138: ['"Remove Classes from Global Namespace"]].
* [@https://github.com/boostorg/container/issues/142 GitHub #142: ['"memset called with null pointer"]].
[endsect]

View File

@@ -587,8 +587,10 @@ inline typename dtl::enable_if_memzero_initializable<F, F>::type
uninitialized_value_init_alloc_n(Allocator &, typename boost::container::allocator_traits<Allocator>::size_type n, F r)
{
typedef typename boost::container::iterator_traits<F>::value_type value_type;
std::memset((void*)boost::movelib::iterator_to_raw_pointer(r), 0, sizeof(value_type)*n);
boost::container::iterator_advance(r, n);
if (BOOST_LIKELY(n)){
std::memset((void*)boost::movelib::iterator_to_raw_pointer(r), 0, sizeof(value_type)*n);
boost::container::iterator_advance(r, n);
}
return r;
}
@@ -892,8 +894,10 @@ inline typename dtl::enable_if_memtransfer_copy_assignable<I, F, F>::type
{
typedef typename boost::container::iterator_traits<I>::value_type value_type;
const typename boost::container::iterator_traits<I>::difference_type n = boost::container::iterator_distance(f, l);
r -= n;
std::memmove((boost::movelib::iterator_to_raw_pointer)(r), (boost::movelib::iterator_to_raw_pointer)(f), sizeof(value_type)*n);
if (BOOST_LIKELY(n)){
r -= n;
std::memmove((boost::movelib::iterator_to_raw_pointer)(r), (boost::movelib::iterator_to_raw_pointer)(f), sizeof(value_type)*n);
}
return r;
}