Commit 5bb04e19 authored by neverlord's avatar neverlord

fixed possible overflow

parent 360c43b0
...@@ -9,28 +9,31 @@ ...@@ -9,28 +9,31 @@
namespace cppa { namespace detail { namespace cppa { namespace detail {
std::string demangle(const char* typeid_name) std::string demangle(const char* decorated)
{ {
size_t size; size_t size;
int status; int status;
char* undecorated = abi::__cxa_demangle(typeid_name, NULL, &size, &status); char* undecorated = abi::__cxa_demangle(decorated, nullptr, &size, &status);
if (status != 0) if (status != 0)
{ {
std::string error_msg = "Could not demangle type name "; std::string error_msg = "Could not demangle type name ";
error_msg += typeid_name; error_msg += decorated;
throw std::logic_error(error_msg); throw std::logic_error(error_msg);
} }
std::string result; // the undecorated typeid name std::string result; // the undecorated typeid name
result.reserve(size); result.reserve(size);
const char* cstr = undecorated; const char* cstr = undecorated;
// this loop filter unnecessary characters from undecorated // filter unnecessary characters from undecorated
for (char c = *cstr; c != '\0'; c = *++cstr) char c = *cstr;
while (c != '\0')
{ {
if (c == ' ') if (c == ' ')
{ {
char previous_c = result.empty() ? ' ' : *(result.rbegin()); char previous_c = result.empty() ? ' ' : *(result.rbegin());
// get next non-space character // get next non-space character
do { c = *++cstr; } while (c == ' '); for (c = *++cstr; c == ' '; c = *++cstr) { }
if (c != '\0')
{
// skip whitespace unless it separates two alphanumeric // skip whitespace unless it separates two alphanumeric
// characters (such as in "unsigned int") // characters (such as in "unsigned int")
if (isalnum(c) && isalnum(previous_c)) if (isalnum(c) && isalnum(previous_c))
...@@ -42,10 +45,13 @@ std::string demangle(const char* typeid_name) ...@@ -42,10 +45,13 @@ std::string demangle(const char* typeid_name)
{ {
result += c; result += c;
} }
c = *++cstr;
}
} }
else else
{ {
result += c; result += c;
c = *++cstr;
} }
} }
free(undecorated); free(undecorated);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment