From 2d23488dac42e567e6d4de9ef1b0211c62f7e3e9 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Wed, 22 Mar 2017 21:45:42 +0000 Subject: [PATCH] Cherry-pick libcxxrt commit 8a853717e61d5d55cbdf74d9d0a7545da5d5ff92: Author: David Chisnall Date: Wed Mar 22 12:27:08 2017 +0000 Simplify some code. realloc() with a null pointer is equivalent to malloc, so we don't need to handle the two cases independently. Fixes #46 This should help with lang/beignet and other programs, which expect __cxa_demangle(name, NULL, NULL, &status) to return zero in status. PR: 213732 MFC after: 3 days --- contrib/libcxxrt/typeinfo.cc | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/contrib/libcxxrt/typeinfo.cc b/contrib/libcxxrt/typeinfo.cc index 71de9ae59bd8..5c44ef1fd2ca 100644 --- a/contrib/libcxxrt/typeinfo.cc +++ b/contrib/libcxxrt/typeinfo.cc @@ -86,15 +86,7 @@ extern "C" char* __cxa_demangle(const char* mangled_name, if (NULL != demangled) { size_t len = strlen(demangled); - if (buf == NULL) - { - if (n) - { - *n = len; - } - return demangled; - } - if (*n < len+1) + if (!buf || (*n < len+1)) { buf = static_cast(realloc(buf, len+1)); }