TOKEN::Match : Removed the parameter varnames2 because it's unused and deprecated

This commit is contained in:
Daniel Marjamäki 2008-12-25 18:27:49 +00:00
parent 8c08c4d66b
commit 709e2a4277
4 changed files with 18 additions and 24 deletions

View File

@ -75,7 +75,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const TOKEN *tok, co
// Array index..
if ( varid > 0 )
{
if ( TOKEN::Match(tok, "%varid% [ %num% ]", 0, 0, varid) )
if ( TOKEN::Match(tok, "%varid% [ %num% ]", 0, varid) )
{
const char *num = tok->strAt(2);
if (strtol(num, NULL, 10) >= size)
@ -112,7 +112,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const TOKEN *tok, co
// Array index..
if ( varid > 0 )
{
if ( !tok->isName() && !TOKEN::Match(tok, "[.&]") && TOKEN::Match(tok->next(), "%varid% [ %num% ]", 0, 0, varid) )
if ( !tok->isName() && !TOKEN::Match(tok, "[.&]") && TOKEN::Match(tok->next(), "%varid% [ %num% ]", 0, varid) )
{
const char *num = tok->strAt(3);
if (strtol(num, NULL, 10) >= size)
@ -138,8 +138,8 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const TOKEN *tok, co
{
if ( TOKEN::Match(tok, "memset|memcpy|memmove|memcmp|strncpy|fgets") )
{
if ( TOKEN::Match(tok->next(), "( %varid% , %num% , %num% )", 0, 0, varid) ||
TOKEN::Match(tok->next(), "( %var% , %varid% , %num% )", 0, 0, varid) )
if ( TOKEN::Match(tok->next(), "( %varid% , %num% , %num% )", 0, varid) ||
TOKEN::Match(tok->next(), "( %var% , %varid% , %num% )", 0, varid) )
{
const char *num = tok->strAt(6);
if ( atoi(num) > total_size )

View File

@ -164,7 +164,7 @@ bool TOKEN::simpleMatch(const TOKEN *tok, const char pattern[])
return true;
}
bool TOKEN::Match(const TOKEN *tok, const char pattern[], const char *varname1[], const char *varname2[], unsigned int varid)
bool TOKEN::Match(const TOKEN *tok, const char pattern[], const char *varname1[], unsigned int varid)
{
const char *p = pattern;
while ( *p )
@ -198,8 +198,6 @@ bool TOKEN::Match(const TOKEN *tok, const char pattern[], const char *varname1[]
if (str[0] == 0)
return true;
bool useVar1;
// Compare the first character of the string for optimization reasons
// before doing more detailed checks.
bool patternIdentified = false;
@ -221,25 +219,23 @@ bool TOKEN::Match(const TOKEN *tok, const char pattern[], const char *varname1[]
}
// Variable name..
else if ((useVar1 = (strcmp(str,"%var1%")==0)) || strcmp(str,"%var2%")==0)
else if (strcmp(str, "%var1%") == 0)
{
const char **varname = useVar1 ? varname1 : varname2;
if ( ! varname )
if ( ! varname1 )
return false;
if (tok->_str != varname[0])
if (tok->_str != varname1[0])
return false;
for ( int i = 1; varname[i]; i++ )
for ( int i = 1; varname1[i]; i++ )
{
if ( !(tok->tokAt(2)) )
return false;
if ( strcmp(tok->strAt( 1), ".") )
if ( strcmp(tok->strAt(1), ".") )
return false;
if ( strcmp(tok->strAt( 2), varname[i]) )
if ( strcmp(tok->strAt(2), varname1[i]) )
return false;
tok = tok->tokAt(2);
@ -353,11 +349,11 @@ bool TOKEN::isStandardType() const
//---------------------------------------------------------------------------
const TOKEN *TOKEN::findmatch(const TOKEN *tok, const char pattern[], const char *varname1[], const char *varname2[])
const TOKEN *TOKEN::findmatch(const TOKEN *tok, const char pattern[], const char *varname1[])
{
for ( ; tok; tok = tok->next())
{
if ( TOKEN::Match(tok, pattern, varname1, varname2) )
if ( TOKEN::Match(tok, pattern, varname1) )
return tok;
}
return 0;

View File

@ -85,7 +85,6 @@ public:
* "%bool%" true or false
* "%str%" Any token starting with "-character (C-string).
* "%var1%" Match with parameter varname1
* "%var2%" Match with parameter varname2
* "%varid%" Match with parameter varid
* "[abc]" Any of the characters 'a' or 'b' or 'c'
* "int|void|char" Any of the strings, int, void or char
@ -102,18 +101,17 @@ public:
* @param tok List of tokens to be compared to the pattern
* @param pattern The pattern against which the tokens are compared,
* e.g. "const" or ") const|volatile| {".
* @param varname1 Used with pattern "%var1%" and "%var2%"
* @param varname2 Used with pattern "%var1%" and "%var2%"
* @param varname1 Used with pattern "%var1%"
* @return true if given token matches with given pattern
* false if given token does not match with given pattern
*/
static bool Match(const TOKEN *tok, const char pattern[], const char *varname1[]=0, const char *varname2[]=0, unsigned int varid=0);
static bool Match(const TOKEN *tok, const char pattern[], const char *varname1[]=0, unsigned int varid=0);
bool isName() const;
bool isNumber() const;
bool isBoolean() const;
bool isStandardType() const;
static const TOKEN *findmatch(const TOKEN *tok, const char pattern[], const char *varname1[]=0, const char *varname2[]=0);
static const TOKEN *findmatch(const TOKEN *tok, const char pattern[], const char *varname1[]=0);
/**
* Needle is build from multiple alternatives. If one of

View File

@ -671,7 +671,7 @@ void Tokenizer::setVarId()
const std::string pattern(std::string("%varid% . ") + tok->strAt(2));
for ( TOKEN *tok2 = tok; tok2; tok2 = tok2->next() )
{
if ( TOKEN::Match(tok2, pattern.c_str(), 0, 0, tok->varId()) )
if ( TOKEN::Match(tok2, pattern.c_str(), 0, tok->varId()) )
tok2->next()->next()->varId( _varId );
}
}
@ -1459,7 +1459,7 @@ bool Tokenizer::simplifyKnownVariables()
break;
// Replace variable with numeric constant..
if ( TOKEN::Match(tok3, "if ( %varid% )", 0, 0, varid) )
if ( TOKEN::Match(tok3, "if ( %varid% )", 0, varid) )
{
tok3 = tok3->next()->next();
tok3->setstr( tok2->strAt(2) );