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

View File

@ -164,7 +164,7 @@ bool TOKEN::simpleMatch(const TOKEN *tok, const char pattern[])
return true; 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; const char *p = pattern;
while ( *p ) while ( *p )
@ -198,8 +198,6 @@ bool TOKEN::Match(const TOKEN *tok, const char pattern[], const char *varname1[]
if (str[0] == 0) if (str[0] == 0)
return true; return true;
bool useVar1;
// Compare the first character of the string for optimization reasons // Compare the first character of the string for optimization reasons
// before doing more detailed checks. // before doing more detailed checks.
bool patternIdentified = false; bool patternIdentified = false;
@ -221,17 +219,15 @@ bool TOKEN::Match(const TOKEN *tok, const char pattern[], const char *varname1[]
} }
// Variable name.. // 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 ( ! varname1 )
if ( ! varname )
return false; return false;
if (tok->_str != varname[0]) if (tok->_str != varname1[0])
return false; return false;
for ( int i = 1; varname[i]; i++ ) for ( int i = 1; varname1[i]; i++ )
{ {
if ( !(tok->tokAt(2)) ) if ( !(tok->tokAt(2)) )
return false; return false;
@ -239,7 +235,7 @@ bool TOKEN::Match(const TOKEN *tok, const char pattern[], const char *varname1[]
if ( strcmp(tok->strAt(1), ".") ) if ( strcmp(tok->strAt(1), ".") )
return false; return false;
if ( strcmp(tok->strAt( 2), varname[i]) ) if ( strcmp(tok->strAt(2), varname1[i]) )
return false; return false;
tok = tok->tokAt(2); 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()) for ( ; tok; tok = tok->next())
{ {
if ( TOKEN::Match(tok, pattern, varname1, varname2) ) if ( TOKEN::Match(tok, pattern, varname1) )
return tok; return tok;
} }
return 0; return 0;

View File

@ -85,7 +85,6 @@ public:
* "%bool%" true or false * "%bool%" true or false
* "%str%" Any token starting with "-character (C-string). * "%str%" Any token starting with "-character (C-string).
* "%var1%" Match with parameter varname1 * "%var1%" Match with parameter varname1
* "%var2%" Match with parameter varname2
* "%varid%" Match with parameter varid * "%varid%" Match with parameter varid
* "[abc]" Any of the characters 'a' or 'b' or 'c' * "[abc]" Any of the characters 'a' or 'b' or 'c'
* "int|void|char" Any of the strings, int, void or char * "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 tok List of tokens to be compared to the pattern
* @param pattern The pattern against which the tokens are compared, * @param pattern The pattern against which the tokens are compared,
* e.g. "const" or ") const|volatile| {". * e.g. "const" or ") const|volatile| {".
* @param varname1 Used with pattern "%var1%" and "%var2%" * @param varname1 Used with pattern "%var1%"
* @param varname2 Used with pattern "%var1%" and "%var2%"
* @return true if given token matches with given pattern * @return true if given token matches with given pattern
* false if given token does not match 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 isName() const;
bool isNumber() const; bool isNumber() const;
bool isBoolean() const; bool isBoolean() const;
bool isStandardType() 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 * 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)); const std::string pattern(std::string("%varid% . ") + tok->strAt(2));
for ( TOKEN *tok2 = tok; tok2; tok2 = tok2->next() ) 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 ); tok2->next()->next()->varId( _varId );
} }
} }
@ -1459,7 +1459,7 @@ bool Tokenizer::simplifyKnownVariables()
break; break;
// Replace variable with numeric constant.. // 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 = tok3->next()->next();
tok3->setstr( tok2->strAt(2) ); tok3->setstr( tok2->strAt(2) );