]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR libstdc++/67554 Do not pass null pointers to memcpy
authorJonathan Wakely <jwakely@redhat.com>
Mon, 14 May 2018 15:35:06 +0000 (16:35 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Mon, 14 May 2018 15:35:06 +0000 (16:35 +0100)
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: r260229

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/valarray_array.h

index 2c0c0d47a7a7ed2dcf79e11eaf256edb2e10e50a..9d47d0081474581044d331b8304bcd81439ccff4 100644 (file)
@@ -1,5 +1,9 @@
 2018-05-14  Jonathan Wakely  <jwakely@redhat.com>
 
+       PR libstdc++/67554
+       * include/bits/valarray_array.h (_Array_copy_ctor<_Tp, true>)
+       (_Array_copier<_Tp, true>): Do not pass null pointers to memcpy.
+
        PR libstdc++/82966
        * include/bits/node_handle.h (_Node_handle_common::_M_swap): Use value
        instead of type.
index f1d2c43044ff2bb2624ee00e3e1eb8ec74ac084b..07f38ed03edf6fd598628093329555f122a70d06 100644 (file)
@@ -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[<>]