From: redi Date: Fri, 9 Nov 2018 20:14:07 +0000 (+0000) Subject: PR libstdc++/87787 fix UBsan error in std::vector X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d64015d25eb056f2c12228156b3b97b85973cd44;p=thirdparty%2Fgcc.git PR libstdc++/87787 fix UBsan error in std::vector 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). git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@265984 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 755b2c20a09c..2a694d96ebda 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,9 @@ +2018-11-09 Jonathan Wakely + + 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 * configure: Regenerated. diff --git a/libstdc++-v3/include/bits/stl_uninitialized.h b/libstdc++-v3/include/bits/stl_uninitialized.h index 94c7e151e29a..8839bfdcc904 100644 --- a/libstdc++-v3/include/bits/stl_uninitialized.h +++ b/libstdc++-v3/include/bits/stl_uninitialized.h @@ -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; }