From c39fbb86db0778bc6d04bbf9c09468870c616885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 6 Nov 2010 13:24:33 +0100 Subject: [PATCH] Tokenizer::simplifyKnownVariables : Fixed TODO test case when simplifying pointer alias in function call --- lib/tokenize.cpp | 20 ++++++++++++++++++++ test/testsimplifytokens.cpp | 17 ++++++++++------- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c7ee59a0a..1c83337a9 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5981,6 +5981,26 @@ bool Tokenizer::simplifyKnownVariables() ret = true; } + // Variable is used in function call.. + if (Token::Match(tok3, "%var% ( %varid% ,", varid)) + { + const char * const functionName[] = + { + "memcmp","memcpy","memmove","memset", + "strcmp","strcpy","strncpy","strdup" + }; + for (unsigned int i = 0; i < (sizeof(functionName) / sizeof(*functionName)); ++i) + { + if (tok3->str() == functionName[i]) + { + Token *par1 = tok3->next()->next(); + par1->str(value); + par1->varId(valueVarId); + break; + } + } + } + // Variable is used in calculation.. if (((tok3->previous()->varId() > 0) && Token::Match(tok3, "& %varid%", varid)) || Token::Match(tok3, "[=+-*/[] %varid% [=?+-*/;])]", varid) || diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index a94307bff..f9365139e 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -5252,15 +5252,18 @@ private: } { - const char code[] = "int a[10];\n" - "int *b = a;\n" - "memset(b,0,sizeof(a));"; + const char code[] = "void f() {\n" + " int a[10];\n" + " int *b = a;\n" + " memset(b,0,sizeof(a));\n" + "}"; - const char expected[] = "int a [ 10 ] ; " - "int * b ; b = a ; " - "memset ( a , 0 , 40 ) ;"; + const char expected[] = "void f ( ) {" + " int a [ 10 ] ;" + " memset ( a , 0 , 40 ) ; " + "}"; - TODO_ASSERT_EQUALS(expected, tok(code)); + ASSERT_EQUALS(expected, tok(code)); } }