From 756c4cdc6a44bff0908a64078054a585b8cbdff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Fri, 14 Feb 2020 05:10:29 +0100 Subject: [PATCH] Fixed #142 ("memset called with null pointer") --- doc/container.qbk | 1 + include/boost/container/detail/copy_move_algo.hpp | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/doc/container.qbk b/doc/container.qbk index c77c487..0cc8bb4 100644 --- a/doc/container.qbk +++ b/doc/container.qbk @@ -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] diff --git a/include/boost/container/detail/copy_move_algo.hpp b/include/boost/container/detail/copy_move_algo.hpp index b71560d..cd55af4 100644 --- a/include/boost/container/detail/copy_move_algo.hpp +++ b/include/boost/container/detail/copy_move_algo.hpp @@ -587,8 +587,10 @@ inline typename dtl::enable_if_memzero_initializable::type uninitialized_value_init_alloc_n(Allocator &, typename boost::container::allocator_traits::size_type n, F r) { typedef typename boost::container::iterator_traits::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::type { typedef typename boost::container::iterator_traits::value_type value_type; const typename boost::container::iterator_traits::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; }