Skip to content

Commit

Permalink
demangle: let abi::__cxa_demangle perform the allocation of the result
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Olivier <[email protected]>
  • Loading branch information
martin-olivier committed Dec 28, 2024
1 parent 018ed3c commit 63c1fea
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions src/demangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,16 @@ std::string demangle_symbol(const char *symbol) {
#include <cstring>

std::string demangle_symbol(const char *symbol) {
size_t size = strlen(symbol);
std::string result;
int status;
char *buf;
char *res;

buf = (char *)(malloc(size));
if (!buf)
throw std::bad_alloc();

res = abi::__cxa_demangle(symbol, buf, &size, &status);
if (!res) {
free(buf);
char *demangled;

demangled = abi::__cxa_demangle(symbol, 0, 0, 0);
if (!demangled)
return "";
}

result = format_symbol(res);
result = format_symbol(demangled);

free(res);
free(demangled);

return result;
}
Expand Down

0 comments on commit 63c1fea

Please sign in to comment.