diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index b6a69e3e6ea4..b675f5ffab50 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,14 @@ 2015-06-08 Jonathan Wakely + PR libstdc++/66354 + * include/bits/stl_algobase.h (__fill_a): Check length before calling + memset. + + PR libstdc++/66327 + * include/bits/stl_algobase.h (__equal::equal): Do not call + memcmp for empty ranges. + (__lexicographical_compare::__lc): Likewise. + Backported from mainline 2015-06-02 Jonathan Wakely diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index 90401350d949..2b69e6189545 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -715,8 +715,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __fill_a(_Tp* __first, _Tp* __last, const _Tp& __c) { const _Tp __tmp = __c; - __builtin_memset(__first, static_cast(__tmp), - __last - __first); + if (const size_t __len = __last - __first) + __builtin_memset(__first, static_cast(__tmp), __len); } /** @@ -822,8 +822,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION static bool equal(const _Tp* __first1, const _Tp* __last1, const _Tp* __first2) { - return !__builtin_memcmp(__first1, __first2, sizeof(_Tp) - * (__last1 - __first1)); + if (const size_t __len = (__last1 - __first1)) + return !__builtin_memcmp(__first1, __first2, sizeof(_Tp) * __len); + return true; } }; @@ -927,9 +928,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { const size_t __len1 = __last1 - __first1; const size_t __len2 = __last2 - __first2; - const int __result = __builtin_memcmp(__first1, __first2, - std::min(__len1, __len2)); - return __result != 0 ? __result < 0 : __len1 < __len2; + if (const size_t __len = std::min(__len1, __len2)) + if (int __result = __builtin_memcmp(__first1, __first2, __len)) + return __result < 0; + return __len1 < __len2; } };