[libcxx] r238666 - Don't try to memcpy zero bytes; sometimes the source pointer is NULL, and that's UB. Thanks to Nuno Lopes for the catch.
David Majnemer
david.majnemer at gmail.com
Sun May 31 01:48:54 PDT 2015
On Sat, May 30, 2015 at 8:13 PM, Marshall Clow <mclow.lists at gmail.com>
wrote:
> Author: marshall
> Date: Sat May 30 22:13:31 2015
> New Revision: 238666
>
> URL: http://llvm.org/viewvc/llvm-project?rev=238666&view=rev
> Log:
> Don't try to memcpy zero bytes; sometimes the source pointer is NULL, and
> that's UB. Thanks to Nuno Lopes for the catch.
>
> Modified:
> libcxx/trunk/include/memory
>
> Modified: libcxx/trunk/include/memory
> URL:
> http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/memory?rev=238666&r1=238665&r2=238666&view=diff
>
> ==============================================================================
> --- libcxx/trunk/include/memory (original)
> +++ libcxx/trunk/include/memory Sat May 30 22:13:31 2015
> @@ -621,6 +621,8 @@ void* align(size_t alignment, size_t siz
> #pragma GCC system_header
> #endif
>
> +extern "C" int printf(const char * __restrict, ...);
> +
>
Was this change intentional?
> _LIBCPP_BEGIN_NAMESPACE_STD
>
> // addressof moved to <__functional_base>
> @@ -1521,7 +1523,8 @@ struct _LIBCPP_TYPE_VIS_ONLY allocator_t
> __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_t
> {
> 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_t
> {
> 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:
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150531/9cf97062/attachment.html>
More information about the cfe-commits
mailing list