Change __sanitizer_symbolize_demangle hook return type to 'int'
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@185326 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cc b/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cc
index 2588dd1..4f0b2ab 100644
--- a/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cc
+++ b/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cc
@@ -191,8 +191,8 @@
SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE
void __sanitizer_symbolize_flush();
SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE
-void __sanitizer_symbolize_demangle(const char *Name, char *Buffer,
- int MaxLength);
+int __sanitizer_symbolize_demangle(const char *Name, char *Buffer,
+ int MaxLength);
} // extern "C"
class InternalSymbolizer {
@@ -223,10 +223,18 @@
const char *Demangle(const char *name) {
if (__sanitizer_symbolize_demangle) {
- char *res = static_cast<char*>(InternalAlloc(kMaxDemangledNameSize));
- internal_memset(res, 0, kMaxDemangledNameSize);
- __sanitizer_symbolize_demangle(name, res, kMaxDemangledNameSize);
- return res;
+ for (uptr res_length = 1024;
+ res_length <= InternalSizeClassMap::kMaxSize;) {
+ char *res_buff = static_cast<char*>(InternalAlloc(res_length));
+ uptr req_length =
+ __sanitizer_symbolize_demangle(name, res_buff, res_length);
+ if (req_length > res_length) {
+ res_length = req_length + 1;
+ InternalFree(res_buff);
+ continue;
+ }
+ return res_buff;
+ }
}
return name;
}