This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[patch] libstdc++/66354 don't pass null pointers to memset
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Sun, 31 May 2015 23:42:59 +0100
- Subject: [patch] libstdc++/66354 don't pass null pointers to memset
- Authentication-results: sourceware.org; auth=none
Another error caught by ubsan.
Tested powerpc64le-linux, committed to trunk.
commit 3415b9186469cf4b94fa2f141c6e69e5db77f118
Author: Jonathan Wakely <jwakely@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);
}
/**