diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2015-05-29 14:28:54 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2015-05-29 14:28:54 +0100 |
commit | 6759eddee476abdfb5e847a7de3765309f4f1e2d (patch) | |
tree | 3715a94926f2e666ec7040720bff322b87087c1c /libstdc++-v3 | |
parent | ca382af0c82a750538c97187c6a2a2f721d0812d (diff) | |
download | gcc-6759eddee476abdfb5e847a7de3765309f4f1e2d.zip gcc-6759eddee476abdfb5e847a7de3765309f4f1e2d.tar.gz gcc-6759eddee476abdfb5e847a7de3765309f4f1e2d.tar.bz2 |
re PR libstdc++/66327 (-fsanitize=nonnull-attribute errors in stl_algobase.h)
PR libstdc++/66327
* include/bits/stl_algobase.h (__equal<true>::equal): Do not call
memcmp with null pointers.
(__lexicographical_compare<true>::__lc): Do not call memcmp for empty
ranges.
From-SVN: r223865
Diffstat (limited to 'libstdc++-v3')
-rw-r--r-- | libstdc++-v3/ChangeLog | 8 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_algobase.h | 15 |
2 files changed, 20 insertions, 3 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 286197c..94c7963 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2015-05-29 Jonathan Wakely <jwakely@redhat.com> + + PR libstdc++/66327 + * include/bits/stl_algobase.h (__equal<true>::equal): Do not call + memcmp with null pointers. + (__lexicographical_compare<true>::__lc): Do not call memcmp for empty + ranges. + 2015-05-28 Jonathan Wakely <jwakely@redhat.com> PR libstdc++/65352 diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index 409ef36..db065e2 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -812,6 +812,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION static bool equal(const _Tp* __first1, const _Tp* __last1, const _Tp* __first2) { + if (__first1 == 0 || __first2 == 0) + return __first1 == __last1; + return !__builtin_memcmp(__first1, __first2, sizeof(_Tp) * (__last1 - __first1)); } @@ -917,9 +920,15 @@ _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 (__len1 && __len2) + { + if (int __result = __builtin_memcmp(__first1, __first2, + std::min(__len1, __len2))) + { + return __result < 0; + } + } + return __len1 < __len2; } }; |