summaryrefslogtreecommitdiff
path: root/include/memory
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2015-05-31 03:13:31 +0000
committerMarshall Clow <mclow.lists@gmail.com>2015-05-31 03:13:31 +0000
commitbf0460e0a0045dcf418fc065d5bf0875f77f3bbf (patch)
tree16a2fd49b854a834f91a60895a4a83e7d5ee26f8 /include/memory
parent0620fc865b076da2abf24884e34393b337e7ee47 (diff)
Don't try to memcpy zero bytes; sometimes the source pointer is NULL, and that's UB. Thanks to Nuno Lopes for the catch.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@238666 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/memory')
-rw-r--r--include/memory11
1 files changed, 8 insertions, 3 deletions
diff --git a/include/memory b/include/memory
index a0e7a8bcc..a004c89d5 100644
--- a/include/memory
+++ b/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: