Fixed #716 (segmentation fault: sizeof string)
This commit is contained in:
parent
9d65a1ebe8
commit
0e729fedc0
|
@ -1291,6 +1291,31 @@ bool Tokenizer::createLinks()
|
|||
|
||||
void Tokenizer::simplifySizeof()
|
||||
{
|
||||
// Replace 'sizeof(str)'
|
||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||
{
|
||||
if (tok->str() != "sizeof")
|
||||
continue;
|
||||
|
||||
if (Token::Match(tok, "sizeof %str%"))
|
||||
{
|
||||
tok->deleteThis();
|
||||
std::ostringstream ostr;
|
||||
ostr << (strlen(tok->str().c_str()) - 1);
|
||||
tok->str(ostr.str());
|
||||
}
|
||||
|
||||
if (Token::Match(tok, "sizeof ( %str% )"))
|
||||
{
|
||||
tok->deleteThis();
|
||||
tok->deleteThis();
|
||||
tok->deleteNext();
|
||||
std::ostringstream ostr;
|
||||
ostr << (strlen(tok->str().c_str()) - 1);
|
||||
tok->str(ostr.str());
|
||||
}
|
||||
}
|
||||
|
||||
// Fill the map _typeSize..
|
||||
_typeSize.clear();
|
||||
_typeSize["char"] = sizeof(char);
|
||||
|
|
|
@ -662,6 +662,15 @@ private:
|
|||
|
||||
TODO_ASSERT_EQUALS(expected.str(), sizeof_(code));
|
||||
}
|
||||
|
||||
// ticket #716 - sizeof string
|
||||
{
|
||||
std::ostringstream expected;
|
||||
expected << "; " << (sizeof "123");
|
||||
|
||||
ASSERT_EQUALS(expected.str(), sizeof_("; sizeof \"123\""));
|
||||
ASSERT_EQUALS(expected.str(), sizeof_("; sizeof(\"123\")"));
|
||||
}
|
||||
}
|
||||
|
||||
void casting()
|
||||
|
|
Loading…
Reference in New Issue