diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2015-05-31 03:13:31 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2015-05-31 03:13:31 +0000 |
commit | 87601bef58c4410989a1010f6ac550f84421653a (patch) | |
tree | a82cbb4c8e83ddd5938cd36f73f5a5fcb19ffb75 /libcxx | |
parent | 3dbd7ae0e36ddf669982c528cb21b520279ec802 (diff) | |
download | bcm5719-llvm-87601bef58c4410989a1010f6ac550f84421653a.tar.gz bcm5719-llvm-87601bef58c4410989a1010f6ac550f84421653a.zip |
Don't try to memcpy zero bytes; sometimes the source pointer is NULL, and that's UB. Thanks to Nuno Lopes for the catch.
llvm-svn: 238666
Diffstat (limited to 'libcxx')
-rw-r--r-- | libcxx/include/memory | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/libcxx/include/memory b/libcxx/include/memory index a0e7a8bccc9..a004c89d52a 100644 --- a/libcxx/include/memory +++ b/libcxx/include/memory @@ -621,6 +621,8 @@ void* align(size_t alignment, size_t size, void*& ptr, size_t& space); #pragma GCC system_header #endif +extern "C" int printf(const char * __restrict, ...); + _LIBCPP_BEGIN_NAMESPACE_STD // addressof moved to <__functional_base> @@ -1521,7 +1523,8 @@ struct _LIBCPP_TYPE_VIS_ONLY allocator_traits __construct_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2) { ptrdiff_t _Np = __end1 - __begin1; - _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp)); + if (_Np > 0) + _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp)); __begin2 += _Np; } @@ -1549,7 +1552,8 @@ struct _LIBCPP_TYPE_VIS_ONLY allocator_traits { typedef typename remove_const<_Tp>::type _Vp; ptrdiff_t _Np = __end1 - __begin1; - _VSTD::memcpy(const_cast<_Vp*>(__begin2), __begin1, _Np * sizeof(_Tp)); + if (_Np > 0) + _VSTD::memcpy(const_cast<_Vp*>(__begin2), __begin1, _Np * sizeof(_Tp)); __begin2 += _Np; } @@ -1580,7 +1584,8 @@ struct _LIBCPP_TYPE_VIS_ONLY allocator_traits { ptrdiff_t _Np = __end1 - __begin1; __end2 -= _Np; - _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp)); + if (_Np > 0) + _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp)); } private: |