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.

	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: r224230
This commit is contained in:
Jonathan Wakely 2015-06-08 15:19:10 +01:00 committed by Jonathan Wakely
parent dceb39ad4f
commit 22d67dee6f
2 changed files with 18 additions and 7 deletions

View 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.
Backported from mainline
2015-06-02 Jonathan Wakely <jwakely@redhat.com>

View File

@ -715,8 +715,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);
}
/**
@ -822,8 +822,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;
}
};
@ -927,9 +928,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;
}
};