]> 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 22:35:44 +0000 (23:35 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Mon, 14 May 2018 22:35:44 +0000 (23: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: r260244

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

index b003c5951e3c132abe10356ee54357a2e49b7396..6ecaada6df6a2f0b869ae37edae2ec6566948482 100644 (file)
@@ -1,3 +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.
+
 2018-05-10  Jonathan Wakely  <jwakely@redhat.com>
 
        * doc/xml/manual/debug_mode.xml: Add array and forward_list to list
index d6f8e7a23fc6a82f554b3535c19ee64d224f304a..4df1181600e946004d32e8dc2374cbc101d87420 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[<>]