diff options
author | Kelebek1 <eeeedddccc@hotmail.co.uk> | 2023-01-14 20:53:55 +0100 |
---|---|---|
committer | Kelebek1 <eeeedddccc@hotmail.co.uk> | 2023-01-14 20:53:55 +0100 |
commit | 42b16bb33ab0a0bb5b8e4032753fbe67bc85844f (patch) | |
tree | 329775ff39c761ad64ee9a045edd5a983677d90b /src/common | |
parent | Move demangle impl to cpp (diff) | |
download | yuzu-42b16bb33ab0a0bb5b8e4032753fbe67bc85844f.tar yuzu-42b16bb33ab0a0bb5b8e4032753fbe67bc85844f.tar.gz yuzu-42b16bb33ab0a0bb5b8e4032753fbe67bc85844f.tar.bz2 yuzu-42b16bb33ab0a0bb5b8e4032753fbe67bc85844f.tar.lz yuzu-42b16bb33ab0a0bb5b8e4032753fbe67bc85844f.tar.xz yuzu-42b16bb33ab0a0bb5b8e4032753fbe67bc85844f.tar.zst yuzu-42b16bb33ab0a0bb5b8e4032753fbe67bc85844f.zip |
Diffstat (limited to '')
-rw-r--r-- | src/common/demangle.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/common/demangle.cpp b/src/common/demangle.cpp index 17abdb85e..f4246f666 100644 --- a/src/common/demangle.cpp +++ b/src/common/demangle.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "common/demangle.h" +#include "common/scope_exit.h" namespace llvm { char* itaniumDemangle(const char* mangled_name, char* buf, size_t* n, int* status); @@ -13,10 +14,16 @@ std::string DemangleSymbol(const std::string& mangled) { auto is_itanium = [](const std::string& name) -> bool { // A valid Itanium encoding requires 1-4 leading underscores, followed by 'Z'. auto pos = name.find_first_not_of('_'); - return pos > 0 && pos <= 4 && name[pos] == 'Z'; + return pos > 0 && pos <= 4 && pos < name.size() && name[pos] == 'Z'; }; + if (mangled.empty()) { + return mangled; + } + char* demangled = nullptr; + SCOPE_EXIT({ std::free(demangled); }); + if (is_itanium(mangled)) { demangled = llvm::itaniumDemangle(mangled.c_str(), nullptr, nullptr, nullptr); } @@ -24,10 +31,7 @@ std::string DemangleSymbol(const std::string& mangled) { if (!demangled) { return mangled; } - - std::string ret = demangled; - std::free(demangled); - return ret; + return demangled; } } // namespace Common |