diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 470bf818a..33b87b410 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -1301,7 +1301,7 @@ void Tokenizer::simplifySizeof() { tok->deleteThis(); std::ostringstream ostr; - ostr << (strlen(tok->str().c_str()) - 1); + ostr << Token::getStrLength(tok) + 1; tok->str(ostr.str()); } @@ -1311,7 +1311,7 @@ void Tokenizer::simplifySizeof() tok->deleteThis(); tok->deleteNext(); std::ostringstream ostr; - ostr << (strlen(tok->str().c_str()) - 1); + ostr << Token::getStrLength(tok) + 1; tok->str(ostr.str()); } } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index f43f08ad8..0a0d5f3b1 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -671,6 +671,12 @@ private: 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()