From 5d946f4228927be06c03256059e0f0cf7c5408f7 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Sun, 31 May 2015 23:42:17 +0100 Subject: [PATCH] re PR libstdc++/66354 ([UBSAN] stl_algobase.h:708:7: runtime error: null pointer passed as argument) PR libstdc++/66354 * include/bits/stl_algobase.h (__fill_a): Check length before calling memset. From-SVN: r223906 --- libstdc++-v3/ChangeLog | 6 ++++++ libstdc++-v3/include/bits/stl_algobase.h | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 19a4c14eaca..599a3fb525e 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,9 @@ +2015-05-31 Jonathan Wakely + + PR libstdc++/66354 + * include/bits/stl_algobase.h (__fill_a): Check length before calling + memset. + 2015-05-30 Jonathan Wakely * include/bits/stl_algobase.h (__equal::equal): Check length diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index 12eb7ec61f8..703e91c34e0 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(__tmp), - __last - __first); + if (const size_t __len = __last - __first) + __builtin_memset(__first, static_cast(__tmp), __len); } /** -- 2.30.2