re PR libstdc++/66354 ([UBSAN] stl_algobase.h:708:7: runtime error: null pointer...
authorJonathan Wakely <jwakely@redhat.com>
Sun, 31 May 2015 22:42:17 +0000 (23:42 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Sun, 31 May 2015 22:42:17 +0000 (23:42 +0100)
PR libstdc++/66354
* include/bits/stl_algobase.h (__fill_a): Check length before calling
memset.

From-SVN: r223906

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

index 19a4c14eaca1041a7827c0df135661fc4ea2b0ad..599a3fb525edc21bbe3ac36b7f39166290cb01d3 100644 (file)
@@ -1,3 +1,9 @@
+2015-05-31  Jonathan Wakely  <jwakely@redhat.com>
+
+       PR libstdc++/66354
+       * include/bits/stl_algobase.h (__fill_a): Check length before calling
+       memset.
+
 2015-05-30  Jonathan Wakely  <jwakely@redhat.com>
 
        * include/bits/stl_algobase.h (__equal<true>::equal): Check length
index 12eb7ec61f80c902a266724b15d8bf20c50c6619..703e91c34e006d789fe9bc1a4f4ed071bae38fd8 100644 (file)
@@ -705,8 +705,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);
     }
 
   /**