From: Jonathan Wakely Date: Mon, 14 May 2018 22:35:44 +0000 (+0100) Subject: PR libstdc++/67554 Do not pass null pointers to memcpy X-Git-Tag: releases/gcc-6.5.0~322 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0eaf27ec4888d5052a5cbf4ab33c487339dc8069;p=thirdparty%2Fgcc.git PR libstdc++/67554 Do not pass null pointers to memcpy PR libstdc++/67554 * include/bits/valarray_array.h (_Array_copy_ctor<_Tp, true>) (_Array_copier<_Tp, true>): Do not pass null pointers to memcpy. From-SVN: r260244 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index b003c5951e3c..6ecaada6df6a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,9 @@ +2018-05-14 Jonathan Wakely + + PR libstdc++/67554 + * include/bits/valarray_array.h (_Array_copy_ctor<_Tp, true>) + (_Array_copier<_Tp, true>): Do not pass null pointers to memcpy. + 2018-05-10 Jonathan Wakely * doc/xml/manual/debug_mode.xml: Add array and forward_list to list diff --git a/libstdc++-v3/include/bits/valarray_array.h b/libstdc++-v3/include/bits/valarray_array.h index d6f8e7a23fc6..4df1181600e9 100644 --- a/libstdc++-v3/include/bits/valarray_array.h +++ b/libstdc++-v3/include/bits/valarray_array.h @@ -152,7 +152,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { inline static void _S_do_it(const _Tp* __b, const _Tp* __e, _Tp* __restrict__ __o) - { __builtin_memcpy(__o, __b, (__e - __b) * sizeof(_Tp)); } + { + if (__b) + __builtin_memcpy(__o, __b, (__e - __b) * sizeof(_Tp)); + } }; template @@ -258,7 +261,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { inline static void _S_do_it(const _Tp* __restrict__ __a, size_t __n, _Tp* __restrict__ __b) - { __builtin_memcpy(__b, __a, __n * sizeof (_Tp)); } + { + if (__n != 0) + __builtin_memcpy(__b, __a, __n * sizeof (_Tp)); + } }; // Copy a plain array __a[<__n>] into a play array __b[<>]