Tokenizer::simplifyKnownVariables: Don't simplify 'strcpy(a,"ab"); b=a;'. Ticket: #2031

This commit is contained in:
Daniel Marjamäki 2011-03-03 20:07:56 +01:00
parent 3f0d0446e0
commit d7a6e729b8
2 changed files with 17 additions and 2 deletions

View File

@ -6741,6 +6741,8 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
Token::Match(tok3, ("<<|>> " + structname + " %varid% [+-*/%^|;])]").c_str(), varid) || Token::Match(tok3, ("<<|>> " + structname + " %varid% [+-*/%^|;])]").c_str(), varid) ||
Token::Match(tok3->previous(), ("[=+-*/%^|[] ( " + structname + " %varid%").c_str(), varid)) Token::Match(tok3->previous(), ("[=+-*/%^|[] ( " + structname + " %varid%").c_str(), varid))
{ {
if (value[0] == '\"')
break;
if (!structname.empty()) if (!structname.empty())
{ {
tok3->deleteNext(); tok3->deleteNext();
@ -6857,13 +6859,14 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
// return variable.. // return variable..
if (Token::Match(tok3, "return %varid% %any%", varid) && if (Token::Match(tok3, "return %varid% %any%", varid) &&
isOp(tok3->tokAt(2))) isOp(tok3->tokAt(2)) &&
value[0] != '\"')
{ {
tok3->next()->str(value); tok3->next()->str(value);
tok3->next()->varId(valueVarId); 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->deleteNext();
tok3->next()->str(value); tok3->next()->str(value);

View File

@ -2080,6 +2080,18 @@ private:
"}"; "}";
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); 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() void simplifyKnownVariablesBailOutAssign()