Commit 5bb04e19 authored by neverlord's avatar neverlord

fixed possible overflow

parent 360c43b0
......@@ -9,47 +9,53 @@
namespace cppa { namespace detail {
std::string demangle(const char* typeid_name)
std::string demangle(const char* decorated)
{
size_t size;
int status;
char* undecorated = abi::__cxa_demangle(typeid_name, NULL, &size, &status);
if (status != 0)
{
std::string error_msg = "Could not demangle type name ";
error_msg += typeid_name;
throw std::logic_error(error_msg);
}
std::string result; // the undecorated typeid name
result.reserve(size);
const char* cstr = undecorated;
// this loop filter unnecessary characters from undecorated
for (char c = *cstr; c != '\0'; c = *++cstr)
{
if (c == ' ')
{
char previous_c = result.empty() ? ' ' : *(result.rbegin());
// get next non-space character
do { c = *++cstr; } while (c == ' ');
// skip whitespace unless it separates two alphanumeric
// characters (such as in "unsigned int")
if (isalnum(c) && isalnum(previous_c))
{
result += ' ';
result += c;
}
else
{
result += c;
}
}
else
{
result += c;
}
}
free(undecorated);
return result;
size_t size;
int status;
char* undecorated = abi::__cxa_demangle(decorated, nullptr, &size, &status);
if (status != 0)
{
std::string error_msg = "Could not demangle type name ";
error_msg += decorated;
throw std::logic_error(error_msg);
}
std::string result; // the undecorated typeid name
result.reserve(size);
const char* cstr = undecorated;
// filter unnecessary characters from undecorated
char c = *cstr;
while (c != '\0')
{
if (c == ' ')
{
char previous_c = result.empty() ? ' ' : *(result.rbegin());
// get next non-space character
for (c = *++cstr; c == ' '; c = *++cstr) { }
if (c != '\0')
{
// skip whitespace unless it separates two alphanumeric
// characters (such as in "unsigned int")
if (isalnum(c) && isalnum(previous_c))
{
result += ' ';
result += c;
}
else
{
result += c;
}
c = *++cstr;
}
}
else
{
result += c;
c = *++cstr;
}
}
free(undecorated);
return result;
}
} } // 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