Skip to content

Commit

Permalink
Correctly handling demangle failures
Browse files Browse the repository at this point in the history
  • Loading branch information
zajo committed Aug 25, 2024
1 parent 11dfa37 commit c5db573
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
21 changes: 10 additions & 11 deletions include/boost/leaf/detail/demangle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,26 +185,25 @@ namespace leaf_detail
template <class CharT, class Traits>
std::ostream & demangle_and_print(std::basic_ostream<CharT, Traits> & os, char const * mangled_name)
{
#if defined(BOOST_LEAF_CFG_DIAGNOSTICS) && defined(BOOST_LEAF_HAS_CXXABI_H)
BOOST_LEAF_ASSERT(mangled_name);
struct del
#if defined(BOOST_LEAF_CFG_DIAGNOSTICS) && defined(BOOST_LEAF_HAS_CXXABI_H)
struct raii
{
char const * demangled_name;
del(char const * name) noexcept
char * demangled_name;
raii(char const * mangled_name) noexcept
{
int status = 0;
std::size_t size = 0;
demangled_name = abi::__cxa_demangle(name, NULL, &size, &status);
demangled_name = abi::__cxa_demangle(mangled_name, nullptr, nullptr, &status);
}
~del() noexcept
~raii() noexcept
{
std::free(const_cast< char* >(demangled_name));
std::free(demangled_name);
}
} d(mangled_name);
return os << d.demangled_name;
#else
return os << mangled_name;
if( d.demangled_name )
return os << d.demangled_name;
#endif
return os << mangled_name;
}
}

Expand Down
2 changes: 1 addition & 1 deletion include/boost/leaf/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct BOOST_LEAF_SYMBOL_VISIBLE e_source_location
template <class CharT, class Traits>
friend std::ostream & operator<<( std::basic_ostream<CharT, Traits> & os, e_source_location const & x )
{
return os << leaf::parse_name<e_source_location>() << x.file << '(' << x.line << ") in function " << x.function;
return os << leaf::parse_name<e_source_location>() << ": " << x.file << '(' << x.line << ") in function " << x.function;
}
};

Expand Down

0 comments on commit c5db573

Please sign in to comment.