public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-4452] libstdc++: Add error handler for <stacktrace> Date: Fri, 2 Dec 2022 00:18:21 +0000 (GMT) [thread overview] Message-ID: <20221202001821.7A2F9385841C@sourceware.org> (raw) https://gcc.gnu.org/g:40adb39566c6e06809fc63ccade8d25bdfc8dd24 commit r13-4452-g40adb39566c6e06809fc63ccade8d25bdfc8dd24 Author: Björn Schäpers <bjoern@hazardy.de> Date: Wed Nov 30 12:04:16 2022 +0000 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. Diff: --- libstdc++-v3/include/std/stacktrace | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/libstdc++-v3/include/std/stacktrace b/libstdc++-v3/include/std/stacktrace index e7cbbee5638..ec3335e89d8 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();
reply other threads:[~2022-12-02 0:18 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20221202001821.7A2F9385841C@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).