Commit 5bb04e19 authored by neverlord's avatar neverlord

fixed possible overflow

parent 360c43b0
...@@ -9,47 +9,53 @@ ...@@ -9,47 +9,53 @@
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()); {
// get next non-space character char previous_c = result.empty() ? ' ' : *(result.rbegin());
do { c = *++cstr; } while (c == ' '); // get next non-space character
// skip whitespace unless it separates two alphanumeric for (c = *++cstr; c == ' '; c = *++cstr) { }
// characters (such as in "unsigned int") if (c != '\0')
if (isalnum(c) && isalnum(previous_c)) {
{ // skip whitespace unless it separates two alphanumeric
result += ' '; // characters (such as in "unsigned int")
result += c; if (isalnum(c) && isalnum(previous_c))
} {
else result += ' ';
{ result += c;
result += c; }
} else
} {
else result += c;
{ }
result += c; c = *++cstr;
} }
} }
free(undecorated); else
return result; {
result += c;
c = *++cstr;
}
}
free(undecorated);
return result;
} }
} } // namespace cppa::detail } } // namespace cppa::detail
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