diff options
author | Björn Schäpers <bjoern@hazardy.de> | 2022-11-30 12:04:16 +0000 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2022-12-02 00:17:42 +0000 |
commit | 40adb39566c6e06809fc63ccade8d25bdfc8dd24 (patch) | |
tree | 278b79a066864a3dd80caf1ba7e48bf6593321d1 /libstdc++-v3 | |
parent | de144fdab17dbbb64ccb540056ab78b4ffb3fbbc (diff) | |
download | gcc-40adb39566c6e06809fc63ccade8d25bdfc8dd24.zip gcc-40adb39566c6e06809fc63ccade8d25bdfc8dd24.tar.gz gcc-40adb39566c6e06809fc63ccade8d25bdfc8dd24.tar.bz2 |
libstdc++: Add error handler for <stacktrace>
Not providing an error handler results in a null pointer dereference
when an error occurs.
Co-authored-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:
* include/std/stacktrace (stacktrace_entry::_S_err_handler): New
static function.
(stacktrace_entry, basic_stacktrace): Pass &_S_err_handler to
all calls to libbacktrace.
Diffstat (limited to 'libstdc++-v3')
-rw-r--r-- | libstdc++-v3/include/std/stacktrace | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/libstdc++-v3/include/std/stacktrace b/libstdc++-v3/include/std/stacktrace index e7cbbee..ec3335e 100644 --- a/libstdc++-v3/include/std/stacktrace +++ b/libstdc++-v3/include/std/stacktrace @@ -155,11 +155,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _Allocator> friend class basic_stacktrace; + static void _S_err_handler(void*, const char*, int) { } + static __glibcxx_backtrace_state* _S_init() { static __glibcxx_backtrace_state* __state - = __glibcxx_backtrace_create_state(nullptr, 1, nullptr, nullptr); + = __glibcxx_backtrace_create_state(nullptr, 1, _S_err_handler, nullptr); return __state; } @@ -192,7 +194,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __function != nullptr; }; const auto __state = _S_init(); - if (::__glibcxx_backtrace_pcinfo(__state, _M_pc, +__cb, nullptr, &__data)) + if (::__glibcxx_backtrace_pcinfo(__state, _M_pc, +__cb, _S_err_handler, + &__data)) return true; if (__desc && __desc->empty()) { @@ -201,8 +204,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if (__symname) *static_cast<_Data*>(__data)->_M_desc = _S_demangle(__symname); }; - if (::__glibcxx_backtrace_syminfo(__state, _M_pc, +__cb2, nullptr, - &__data)) + if (::__glibcxx_backtrace_syminfo(__state, _M_pc, +__cb2, + _S_err_handler, &__data)) return true; } return false; @@ -252,7 +255,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if (auto __cb = __ret._M_prepare()) [[likely]] { auto __state = stacktrace_entry::_S_init(); - if (__glibcxx_backtrace_simple(__state, 1, __cb, nullptr, + if (__glibcxx_backtrace_simple(__state, 1, __cb, + stacktrace_entry::_S_err_handler, std::__addressof(__ret))) __ret._M_clear(); } @@ -270,7 +274,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if (auto __cb = __ret._M_prepare()) [[likely]] { auto __state = stacktrace_entry::_S_init(); - if (__glibcxx_backtrace_simple(__state, __skip + 1, __cb, nullptr, + if (__glibcxx_backtrace_simple(__state, __skip + 1, __cb, + stacktrace_entry::_S_err_handler, std::__addressof(__ret))) __ret._M_clear(); } @@ -294,7 +299,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { auto __state = stacktrace_entry::_S_init(); int __err = __glibcxx_backtrace_simple(__state, __skip + 1, __cb, - nullptr, + stacktrace_entry::_S_err_handler, std::__addressof(__ret)); if (__err < 0) __ret._M_clear(); |