common/BackTrace: do not use len for length of demangled symbol 37261/head
authorKefu Chai <kchai@redhat.com>
Sun, 20 Sep 2020 03:30:26 +0000 (11:30 +0800)
committerKefu Chai <kchai@redhat.com>
Sun, 20 Sep 2020 03:34:53 +0000 (11:34 +0800)
it turns out `len` is longer than the length of demangled symbol,
let's rely on the `\0` sentry in the returned char* string instead.

in this change, use `status` to tell if the demangle is successful or
not.

Fixes: https://tracker.ceph.com/issues/47552
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/common/BackTrace.cc

index 1dfa39cda1762b421f7c260a2030e7a8528ad14f..e6396afe3a7391e5da5539b4109dfcdcca0a75df 100644 (file)
@@ -52,10 +52,10 @@ std::string BackTrace::demangle(const char* name)
     // only demangle a C++ mangled name
     if (mangled.compare(0, 2, "_Z") == 0) {
       // let __cxa_demangle do the malloc
-      size_t len = 0;
-      if (char* demangled = abi::__cxa_demangle(mangled.c_str(), nullptr, &len, &status)) {
+      char* demangled = abi::__cxa_demangle(mangled.c_str(), nullptr, nullptr, &status);
+      if (!status) {
         std::string full_name{OPEN};
-        full_name += std::string_view(demangled, len);
+        full_name += demangled;
         full_name += end;
         // buf could be reallocated, so free(demangled) instead
         free(demangled);