Tokenizer::simplifyKnownVariables : Fixed TODO test case when simplifying pointer alias in function call
This commit is contained in:
parent
13c2a73d3f
commit
c39fbb86db
|
@ -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) ||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue