mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-24 03:32:35 +08:00
[libc++] Avoid UB in the no-exceptions mode in a few places
Summary: A few places in the library seem to behave unexpectedly when the library is compiled or used with exceptions disabled. For example, not throwing an exception when a pointer is NULL can lead us to dereference the pointer later on, which is UB. This patch fixes such occurences. It's hard to tell whether there are other places where the no-exceptions mode misbehaves like this, because the replacement for throwing an exception does not always seem to be abort()ing, but at least this patch will improve the situation somewhat. See http://lists.llvm.org/pipermail/libcxx-dev/2019-January/000172.html Reviewers: mclow.lists, EricWF Subscribers: christof, jkorous, dexonsmith, libcxx-commits Differential Revision: https://reviews.llvm.org/D57761 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@353850 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -1602,10 +1602,8 @@ _Tp&
|
||||
unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k)
|
||||
{
|
||||
iterator __i = find(__k);
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
if (__i == end())
|
||||
throw out_of_range("unordered_map::at: key not found");
|
||||
#endif // _LIBCPP_NO_EXCEPTIONS
|
||||
__throw_out_of_range("unordered_map::at: key not found");
|
||||
return __i->second;
|
||||
}
|
||||
|
||||
@@ -1614,10 +1612,8 @@ const _Tp&
|
||||
unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const
|
||||
{
|
||||
const_iterator __i = find(__k);
|
||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||
if (__i == end())
|
||||
throw out_of_range("unordered_map::at: key not found");
|
||||
#endif // _LIBCPP_NO_EXCEPTIONS
|
||||
__throw_out_of_range("unordered_map::at: key not found");
|
||||
return __i->second;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user