Another error caught by ubsan.

Tested powerpc64le-linux, committed to trunk.

commit 3415b9186469cf4b94fa2f141c6e69e5db77f118
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Sun May 31 22:40:28 2015 +0100

    	PR libstdc++/66354
    	* include/bits/stl_algobase.h (__fill_a): Check length before calling
    	memset.

diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h
index 12eb7ec..703e91c 100644
--- a/libstdc++-v3/include/bits/stl_algobase.h
+++ b/libstdc++-v3/include/bits/stl_algobase.h
@@ -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);
     }
 
   /**

Reply via email to