diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 7bd917d21..cd1baa565 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -6741,6 +6741,8 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign Token::Match(tok3, ("<<|>> " + structname + " %varid% [+-*/%^|;])]").c_str(), varid) || Token::Match(tok3->previous(), ("[=+-*/%^|[] ( " + structname + " %varid%").c_str(), varid)) { + if (value[0] == '\"') + break; if (!structname.empty()) { tok3->deleteNext(); @@ -6857,13 +6859,14 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign // return variable.. if (Token::Match(tok3, "return %varid% %any%", varid) && - isOp(tok3->tokAt(2))) + isOp(tok3->tokAt(2)) && + value[0] != '\"') { tok3->next()->str(value); tok3->next()->varId(valueVarId); } - else if (pointeralias && Token::Match(tok3, "return * %varid% ;", varid)) + else if (pointeralias && Token::Match(tok3, "return * %varid% ;", varid) && value[0] != '\"') { tok3->deleteNext(); tok3->next()->str(value); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 72763bc01..04697796f 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -2080,6 +2080,18 @@ private: "}"; ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); } + + { + const char code[] = "void f(char *p, char *q) {" + " strcpy(p, \"abc\");" + " q = p;" + "}"; + const char expected[] = "void f ( char * p , char * q ) {" + " strcpy ( p , \"abc\" ) ;" + " q = p ; " + "}"; + ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); + } } void simplifyKnownVariablesBailOutAssign()