diff options
| author | Louis Dionne <ldionne@apple.com> | 2019-02-12 16:06:02 +0000 |
|---|---|---|
| committer | Louis Dionne <ldionne@apple.com> | 2019-02-12 16:06:02 +0000 |
| commit | 7232a84e686a0d1bf834a845e4e59c5594ae8957 (patch) | |
| tree | 195b6c40e1303e25ea40e4e2bc4829a081d7231a /libcxx/include/ios | |
| parent | d694160e665eb3cefc93a07af8232aec0b7d2410 (diff) | |
| download | bcm5719-llvm-7232a84e686a0d1bf834a845e4e59c5594ae8957.tar.gz bcm5719-llvm-7232a84e686a0d1bf834a845e4e59c5594ae8957.zip | |
[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
llvm-svn: 353850
Diffstat (limited to 'libcxx/include/ios')
| -rw-r--r-- | libcxx/include/ios | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/libcxx/include/ios b/libcxx/include/ios index 96336396302..96e84eb3835 100644 --- a/libcxx/include/ios +++ b/libcxx/include/ios @@ -425,6 +425,16 @@ public: virtual ~failure() throw(); }; +_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY +void __throw_failure(char const* __msg) { +#ifndef _LIBCPP_NO_EXCEPTIONS + throw ios_base::failure(__msg); +#else + ((void)__msg); + _VSTD::abort(); +#endif +} + class _LIBCPP_TYPE_VIS ios_base::Init { public: |

