From d7a6e729b84a72b3886dedb8fa7b50db3c68de3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 3 Mar 2011 20:07:56 +0100 Subject: [PATCH] Tokenizer::simplifyKnownVariables: Don't simplify 'strcpy(a,"ab"); b=a;'. Ticket: #2031 --- lib/tokenize.cpp | 7 +++++-- test/testtokenize.cpp | 12 ++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) 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()