@@ -405,11 +405,11 @@ void CheckBufferOverrun::checkFunctionParameter(const Token &ftok, unsigned int
405405 break ;
406406
407407 if (ftok2->varId () == parameter->declarationId ()) {
408- if (Token::Match (ftok2->previous (), " -- %var %" ) ||
409- Token::Match (ftok2, " %var % --" ))
408+ if (Token::Match (ftok2->previous (), " -- %name %" ) ||
409+ Token::Match (ftok2, " %name % --" ))
410410 break ;
411411
412- if (Token::Match (ftok2->previous (), " ;|{|}|%op% %var % [ %num% ]" )) {
412+ if (Token::Match (ftok2->previous (), " ;|{|}|%op% %name % [ %num% ]" )) {
413413 const MathLib::bigint index = MathLib::toLongNumber (ftok2->strAt (2 ));
414414 if (index >= 0 && arrayInfo.num (0 ) > 0 && index >= arrayInfo.num (0 )) {
415415 std::list<const Token *> callstack2 (callstack);
@@ -424,7 +424,7 @@ void CheckBufferOverrun::checkFunctionParameter(const Token &ftok, unsigned int
424424 }
425425
426426 // Calling function..
427- if (Token::Match (ftok2, " %var % (" )) {
427+ if (Token::Match (ftok2, " %name % (" )) {
428428 ArrayInfo ai (arrayInfo);
429429 ai.declarationId (parameter->declarationId ());
430430 checkFunctionCall (ftok2, ai, callstack);
@@ -603,7 +603,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
603603 continue ;
604604
605605 const Token *tok3 = tok->previous ();
606- while (tok3 && Token::Match (tok3->previous (), " %var % ." ))
606+ while (tok3 && Token::Match (tok3->previous (), " %name % ." ))
607607 tok3 = tok3->tokAt (-2 );
608608
609609 // taking address of 1 past end?
@@ -646,9 +646,9 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
646646 if (declarationId == 0 && size > 0 ) {
647647 std::list<const Token *> callstack;
648648 callstack.push_back (tok);
649- if (Token::Match (tok, (" %var % ( " + varnames + " ," ).c_str ()))
649+ if (Token::Match (tok, (" %name % ( " + varnames + " ," ).c_str ()))
650650 checkFunctionParameter (*tok, 1 , arrayInfo, callstack);
651- if (Token::Match (tok, (" %var % ( %var % , " + varnames + " ," ).c_str ()))
651+ if (Token::Match (tok, (" %name % ( %name % , " + varnames + " ," ).c_str ()))
652652 checkFunctionParameter (*tok, 2 , arrayInfo, callstack);
653653 }
654654
@@ -705,7 +705,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
705705 }
706706
707707 // Check function call..
708- if (Token::Match (tok, " %var % (" )) {
708+ if (Token::Match (tok, " %name % (" )) {
709709 // No varid => function calls are not handled
710710 if (declarationId == 0 )
711711 continue ;
@@ -739,7 +739,7 @@ void CheckBufferOverrun::valueFlowCheckArrayIndex(const Token * const tok, const
739739 /*
740740 {
741741 const Token *parent = tok->astParent();
742- while (Token::Match(parent, "%var %|::|*|&"))
742+ while (Token::Match(parent, "%name %|::|*|&"))
743743 parent = parent->astParent();
744744 if (parent && !Token::simpleMatch(parent, "="))
745745 return;
@@ -749,7 +749,7 @@ void CheckBufferOverrun::valueFlowCheckArrayIndex(const Token * const tok, const
749749 bool addressOf = false ;
750750 {
751751 const Token *tok2 = tok->astParent ();
752- while (Token::Match (tok2, " %var %|.|::|[" ))
752+ while (Token::Match (tok2, " %name %|.|::|[" ))
753753 tok2 = tok2->astParent ();
754754 addressOf = tok2 && tok2->str () == " &" && !(tok2->astOperand1 () && tok2->astOperand2 ());
755755 }
@@ -903,7 +903,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo
903903 else if (!tok->scope ()->isExecutable ()) // No executable code outside of executable scope - continue to increase performance
904904 continue ;
905905
906- else if (Token::Match (tok, " %var % (" )) {
906+ else if (Token::Match (tok, " %name % (" )) {
907907 // Check function call..
908908 checkFunctionCall (tok, arrayInfo, std::list<const Token*>());
909909
@@ -1003,7 +1003,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo
10031003// ---------------------------------------------------------------------------
10041004bool CheckBufferOverrun::isArrayOfStruct (const Token* tok, int &position)
10051005{
1006- if (Token::Match (tok->next (), " %var % [ %num% ]" )) {
1006+ if (Token::Match (tok->next (), " %name % [ %num% ]" )) {
10071007 tok = tok->tokAt (4 );
10081008 int i = 1 ;
10091009 for (;;) {
@@ -1284,8 +1284,8 @@ void CheckBufferOverrun::checkStructVariable()
12841284 // dynamically allocated so could be variable sized structure
12851285 if (tok3->next ()->str () == " *" ) {
12861286 // check for allocation
1287- if ((Token::Match (tok3->tokAt (3 ), " ; %var % = malloc ( %num% ) ;" ) ||
1288- (Token::Match (tok3->tokAt (3 ), " ; %var % = (" ) &&
1287+ if ((Token::Match (tok3->tokAt (3 ), " ; %name % = malloc ( %num% ) ;" ) ||
1288+ (Token::Match (tok3->tokAt (3 ), " ; %name % = (" ) &&
12891289 Token::Match (tok3->linkAt (6 ), " ) malloc ( %num% ) ;" ))) &&
12901290 (tok3->strAt (4 ) == tok3->strAt (2 ))) {
12911291 MathLib::bigint size;
@@ -1384,7 +1384,7 @@ void CheckBufferOverrun::bufferOverrun2()
13841384 // singlepass checking using ast, symboldatabase and valueflow
13851385 for (const Token *tok = _tokenizer->tokens (); tok; tok = tok->next ()) {
13861386 // Array index
1387- if (!Token::Match (tok, " %var % [" ))
1387+ if (!Token::Match (tok, " %name % [" ))
13881388 continue ;
13891389
13901390 // TODO: what to do about negative index..
@@ -1578,15 +1578,15 @@ void CheckBufferOverrun::checkBufferAllocatedWithStrlen()
15781578 unsigned int srcVarId;
15791579
15801580 // Look for allocation of a buffer based on the size of a string
1581- if (Token::Match (tok, " %var% = malloc|g_malloc|g_try_malloc ( strlen ( %var % ) )" )) {
1581+ if (Token::Match (tok, " %var% = malloc|g_malloc|g_try_malloc ( strlen ( %name % ) )" )) {
15821582 dstVarId = tok->varId ();
15831583 srcVarId = tok->tokAt (6 )->varId ();
15841584 tok = tok->tokAt (8 );
1585- } else if (Token::Match (tok, " %var% = new char [ strlen ( %var % ) ]" )) {
1585+ } else if (Token::Match (tok, " %var% = new char [ strlen ( %name % ) ]" )) {
15861586 dstVarId = tok->varId ();
15871587 srcVarId = tok->tokAt (7 )->varId ();
15881588 tok = tok->tokAt (9 );
1589- } else if (Token::Match (tok, " %var% = realloc|g_realloc|g_try_realloc ( %var % , strlen ( %var % ) )" )) {
1589+ } else if (Token::Match (tok, " %var% = realloc|g_realloc|g_try_realloc ( %name % , strlen ( %name % ) )" )) {
15901590 dstVarId = tok->varId ();
15911591 srcVarId = tok->tokAt (8 )->varId ();
15921592 tok = tok->tokAt (10 );
@@ -1625,12 +1625,12 @@ void CheckBufferOverrun::checkStringArgument()
16251625 for (std::size_t functionIndex = 0 ; functionIndex < functions; ++functionIndex) {
16261626 const Scope * const scope = symbolDatabase->functionScopes [functionIndex];
16271627 for (const Token *tok = scope->classStart ; tok != scope->classEnd ; tok = tok->next ()) {
1628- if (!Token::Match (tok, " %var % (" ) || !_settings->library .hasminsize (tok->str ()))
1628+ if (!Token::Match (tok, " %name % (" ) || !_settings->library .hasminsize (tok->str ()))
16291629 continue ;
16301630
16311631 unsigned int argnr = 1 ;
16321632 for (const Token *argtok = tok->tokAt (2 ); argtok; argtok = argtok->nextArgument (), argnr++) {
1633- if (!Token::Match (argtok, " %var %|%str% ,|)" ))
1633+ if (!Token::Match (argtok, " %name %|%str% ,|)" ))
16341634 continue ;
16351635 const Token *strtoken = argtok->getValueTokenMinStrSize ();
16361636 if (!strtoken)
@@ -1673,8 +1673,7 @@ void CheckBufferOverrun::checkInsecureCmdLineArgs()
16731673
16741674 } else if (Token::Match (tok, " main ( int %var% , char * * %var% ,|)" )) {
16751675 varid = tok->tokAt (8 )->varId ();
1676- }
1677- if (varid == 0 )
1676+ } else
16781677 continue ;
16791678
16801679 // Jump to the opening curly brace
@@ -1688,15 +1687,15 @@ void CheckBufferOverrun::checkInsecureCmdLineArgs()
16881687
16891688 // Match common patterns that can result in a buffer overrun
16901689 // e.g. strcpy(buffer, argv[0])
1691- if (Token::Match (tok, " strcpy|strcat ( %var % , * %varid%" , varid) ||
1692- Token::Match (tok, " strcpy|strcat ( %var % , %varid% [" , varid)) {
1690+ if (Token::Match (tok, " strcpy|strcat ( %name % , * %varid%" , varid) ||
1691+ Token::Match (tok, " strcpy|strcat ( %name % , %varid% [" , varid)) {
16931692 cmdLineArgsError (tok);
16941693 tok = tok->linkAt (1 );
1695- } else if (Token::Match (tok, " sprintf ( %var % , %str% , %varid% [" , varid) &&
1694+ } else if (Token::Match (tok, " sprintf ( %name % , %str% , %varid% [" , varid) &&
16961695 tok->strAt (4 ).find (" %s" ) != std::string::npos) {
16971696 cmdLineArgsError (tok);
16981697 tok = tok->linkAt (1 );
1699- } else if (Token::Match (tok, " sprintf ( %var % , %str% , * %varid%" , varid) &&
1698+ } else if (Token::Match (tok, " sprintf ( %name % , %str% , * %varid%" , varid) &&
17001699 tok->strAt (4 ).find (" %s" ) != std::string::npos) {
17011700 cmdLineArgsError (tok);
17021701 tok = tok->linkAt (1 );
@@ -1783,12 +1782,10 @@ void CheckBufferOverrun::arrayIndexThenCheck()
17831782 for (std::size_t i = 0 ; i < functions; ++i) {
17841783 const Scope * const scope = symbolDatabase->functionScopes [i];
17851784 for (const Token *tok = scope->classStart ; tok && tok != scope->classEnd ; tok = tok->next ()) {
1786- if (Token::Match (tok, " %var % [ %var% ]" )) {
1785+ if (Token::Match (tok, " %name % [ %var% ]" )) {
17871786 tok = tok->tokAt (2 );
1788- unsigned int indexID = tok->varId ();
1789- if (!indexID)
1790- continue ;
17911787
1788+ unsigned int indexID = tok->varId ();
17921789 const std::string& indexName (tok->str ());
17931790
17941791 // skip array index..
0 commit comments