]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR libstdc++/66354 ([UBSAN] stl_algobase.h:708:7: runtime error: null pointer...
authorJonathan Wakely <jwakely@redhat.com>
Mon, 8 Jun 2015 14:42:02 +0000 (15:42 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Mon, 8 Jun 2015 14:42:02 +0000 (15:42 +0100)
PR libstdc++/66354
* include/bits/stl_algobase.h (__fill_a): Check length before calling
memset.

PR libstdc++/66327
* include/bits/stl_algobase.h (__equal<true>::equal): Do not call
memcmp for empty ranges.
(__lexicographical_compare<true>::__lc): Likewise.

From-SVN: r224233

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

index dc0a5497c5e06b551695e30fb8c7825b79b407b1..278f4b45d2866f6877d29ec14d576a331340fc90 100644 (file)
@@ -1,5 +1,14 @@
 2015-06-08  Jonathan Wakely  <jwakely@redhat.com>
 
+       PR libstdc++/66354
+       * include/bits/stl_algobase.h (__fill_a): Check length before calling
+       memset.
+
+       PR libstdc++/66327
+       * include/bits/stl_algobase.h (__equal<true>::equal): Do not call
+       memcmp for empty ranges.
+       (__lexicographical_compare<true>::__lc): Likewise.
+
        Backport from mainline
        2015-04-13  Jonathan Wakely  <jwakely@redhat.com>
 
index f7c11e931d7da654163baa24a3055192e5ce75a5..a8d3cc89ee3f12b55e796e322190dc6bb57ac69b 100644 (file)
@@ -711,8 +711,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     __fill_a(_Tp* __first, _Tp* __last, const _Tp& __c)
     {
       const _Tp __tmp = __c;
-      __builtin_memset(__first, static_cast<unsigned char>(__tmp),
-                      __last - __first);
+      if (const size_t __len = __last - __first)
+       __builtin_memset(__first, static_cast<unsigned char>(__tmp), __len);
     }
 
   /**
@@ -818,8 +818,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;
        }
     };
 
@@ -923,9 +924,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;
        }
     };