Tokenizer::simplifySizeof(): use Token::getStrLength().

Fixed wrong result when string contains escaped quotes.

Correction for 0e729fedc0 commit.
This commit is contained in:
Slava Semushin 2009-09-23 22:59:26 +07:00
parent 1ba546407f
commit 313479cf8d
2 changed files with 8 additions and 2 deletions

View File

@ -1301,7 +1301,7 @@ void Tokenizer::simplifySizeof()
{ {
tok->deleteThis(); tok->deleteThis();
std::ostringstream ostr; std::ostringstream ostr;
ostr << (strlen(tok->str().c_str()) - 1); ostr << Token::getStrLength(tok) + 1;
tok->str(ostr.str()); tok->str(ostr.str());
} }
@ -1311,7 +1311,7 @@ void Tokenizer::simplifySizeof()
tok->deleteThis(); tok->deleteThis();
tok->deleteNext(); tok->deleteNext();
std::ostringstream ostr; std::ostringstream ostr;
ostr << (strlen(tok->str().c_str()) - 1); ostr << Token::getStrLength(tok) + 1;
tok->str(ostr.str()); tok->str(ostr.str());
} }
} }

View File

@ -671,6 +671,12 @@ private:
ASSERT_EQUALS(expected.str(), sizeof_("; sizeof \"123\"")); ASSERT_EQUALS(expected.str(), sizeof_("; sizeof \"123\""));
ASSERT_EQUALS(expected.str(), sizeof_("; sizeof(\"123\")")); ASSERT_EQUALS(expected.str(), sizeof_("; sizeof(\"123\")"));
} }
{
std::ostringstream expected;
expected << "; " << sizeof("\"quote\"");
ASSERT_EQUALS(expected.str(), sizeof_("; sizeof(\"\\\"quote\\\"\")"));
}
} }
void casting() void casting()