PR libstdc++/67554 * include/bits/valarray_array.h (_Array_copy_ctor<_Tp, true>) (_Array_copier<_Tp, true>): Do not pass null pointers to memcpy.
Tested powerpc64le-linux, committed to trunk. Backports to follow. There's no new test for this, as we're not able to use sanitizers in the testsuite (something I still hope to fix one day).
commit cd61c4ce0bfd69065018417dfe6f3e03b2010af3 Author: Jonathan Wakely <jwak...@redhat.com> Date: Mon May 14 15:50:16 2018 +0100 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. diff --git a/libstdc++-v3/include/bits/valarray_array.h b/libstdc++-v3/include/bits/valarray_array.h index f1d2c43044f..07f38ed03ed 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<typename _Tp> @@ -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[<>]