PR libstdc++/87787 fix UBsan error in std::vector
authorJonathan Wakely <jwakely@redhat.com>
Fri, 9 Nov 2018 20:14:07 +0000 (20:14 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 9 Nov 2018 20:14:07 +0000 (20:14 +0000)
PR libstdc++/87787
* include/bits/stl_uninitialized.h (__relocate_a_1): Do not call
memmove when there's nothing to copy (and pointers could be null).

From-SVN: r265984

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

index 755b2c2..2a694d9 100644 (file)
@@ -1,3 +1,9 @@
+2018-11-09  Jonathan Wakely  <jwakely@redhat.com>
+
+       PR libstdc++/87787
+       * include/bits/stl_uninitialized.h (__relocate_a_1): Do not call
+       memmove when there's nothing to copy (and pointers could be null).
+
 2018-11-07  Hafiz Abid Qadeer  <abidh@codesourcery.com>
 
        * configure: Regenerated.
index 94c7e15..8839bfd 100644 (file)
@@ -904,7 +904,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                   _Tp* __result, allocator<_Up>& __alloc)
     {
       ptrdiff_t __count = __last - __first;
-      __builtin_memmove(__result, __first, __count * sizeof(_Tp));
+      if (__count > 0)
+       __builtin_memmove(__result, __first, __count * sizeof(_Tp));
       return __result + __count;
     }