@@ -56,9 +56,7 @@ static const struct CWE CWE758(758U); // Reliance on Undefined, Unspecified, o
5656void CheckString::stringLiteralWrite ()
5757{
5858 const SymbolDatabase *symbolDatabase = mTokenizer ->getSymbolDatabase ();
59- const std::size_t functions = symbolDatabase->functionScopes .size ();
60- for (std::size_t i = 0 ; i < functions; ++i) {
61- const Scope * scope = symbolDatabase->functionScopes [i];
59+ for (const Scope * scope : symbolDatabase->functionScopes ) {
6260 for (const Token* tok = scope->bodyStart ->next (); tok != scope->bodyEnd ; tok = tok->next ()) {
6361 if (!tok->variable () || !tok->variable ()->isPointer ())
6462 continue ;
@@ -169,9 +167,7 @@ void CheckString::checkSuspiciousStringCompare()
169167 return ;
170168
171169 const SymbolDatabase* symbolDatabase = mTokenizer ->getSymbolDatabase ();
172- const std::size_t functions = symbolDatabase->functionScopes .size ();
173- for (std::size_t i = 0 ; i < functions; ++i) {
174- const Scope * scope = symbolDatabase->functionScopes [i];
170+ for (const Scope * scope : symbolDatabase->functionScopes ) {
175171 for (const Token* tok = scope->bodyStart ->next (); tok != scope->bodyEnd ; tok = tok->next ()) {
176172 if (tok->tokType () != Token::eComparisonOp)
177173 continue ;
@@ -250,9 +246,7 @@ static bool isChar(const Variable* var)
250246void CheckString::strPlusChar ()
251247{
252248 const SymbolDatabase* symbolDatabase = mTokenizer ->getSymbolDatabase ();
253- const std::size_t functions = symbolDatabase->functionScopes .size ();
254- for (std::size_t i = 0 ; i < functions; ++i) {
255- const Scope * scope = symbolDatabase->functionScopes [i];
249+ for (const Scope * scope : symbolDatabase->functionScopes ) {
256250 for (const Token* tok = scope->bodyStart ->next (); tok != scope->bodyEnd ; tok = tok->next ()) {
257251 if (tok->str () == " +" ) {
258252 if (tok->astOperand1 () && (tok->astOperand1 ()->tokType () == Token::eString)) { // string literal...
@@ -279,9 +273,7 @@ void CheckString::checkIncorrectStringCompare()
279273 return ;
280274
281275 const SymbolDatabase *symbolDatabase = mTokenizer ->getSymbolDatabase ();
282- const std::size_t functions = symbolDatabase->functionScopes .size ();
283- for (std::size_t i = 0 ; i < functions; ++i) {
284- const Scope * scope = symbolDatabase->functionScopes [i];
276+ for (const Scope * scope : symbolDatabase->functionScopes ) {
285277 for (const Token* tok = scope->bodyStart ->next (); tok != scope->bodyEnd ; tok = tok->next ()) {
286278 // skip "assert(str && ..)" and "assert(.. && str)"
287279 if ((endsWith (tok->str (), " assert" , 6 ) || endsWith (tok->str (), " ASSERT" , 6 )) &&
@@ -342,9 +334,7 @@ void CheckString::overlappingStrcmp()
342334 return ;
343335
344336 const SymbolDatabase *symbolDatabase = mTokenizer ->getSymbolDatabase ();
345- const std::size_t functions = symbolDatabase->functionScopes .size ();
346- for (std::size_t i = 0 ; i < functions; ++i) {
347- const Scope * scope = symbolDatabase->functionScopes [i];
337+ for (const Scope * scope : symbolDatabase->functionScopes ) {
348338 for (const Token* tok = scope->bodyStart ->next (); tok != scope->bodyEnd ; tok = tok->next ()) {
349339 if (tok->str () != " ||" )
350340 continue ;
@@ -382,23 +372,21 @@ void CheckString::overlappingStrcmp()
382372 notEquals0.push_back (t);
383373 }
384374
385- for (std::list<const Token *>::const_iterator eq0 = equals0.begin (); eq0 != equals0.end (); ++eq0) {
386- for (std::list<const Token *>::const_iterator ne0 = notEquals0.begin (); ne0 != notEquals0.end (); ++ne0) {
387- const Token *tok1 = *eq0;
388- const Token *tok2 = *ne0;
389- if (!Token::simpleMatch (tok1->previous (), " strcmp (" ))
375+ for (const Token *eq0 : equals0) {
376+ for (const Token * ne0 : notEquals0) {
377+ if (!Token::simpleMatch (eq0->previous (), " strcmp (" ))
390378 continue ;
391- if (!Token::simpleMatch (tok2 ->previous (), " strcmp (" ))
379+ if (!Token::simpleMatch (ne0 ->previous (), " strcmp (" ))
392380 continue ;
393- const std::vector<const Token *> args1 = getArguments (tok1 ->previous ());
394- const std::vector<const Token *> args2 = getArguments (tok2 ->previous ());
381+ const std::vector<const Token *> args1 = getArguments (eq0 ->previous ());
382+ const std::vector<const Token *> args2 = getArguments (ne0 ->previous ());
395383 if (args1.size () != 2 || args2.size () != 2 )
396384 continue ;
397385 if (args1[1 ]->isLiteral () &&
398386 args2[1 ]->isLiteral () &&
399387 args1[1 ]->str () != args2[1 ]->str () &&
400388 isSameExpression (mTokenizer ->isCPP (), true , args1[0 ], args2[0 ], mSettings ->library , true ))
401- overlappingStrcmpError (tok1, tok2 );
389+ overlappingStrcmpError (eq0, ne0 );
402390 }
403391 }
404392 }
@@ -425,9 +413,7 @@ void CheckString::overlappingStrcmpError(const Token *eq0, const Token *ne0)
425413void CheckString::sprintfOverlappingData ()
426414{
427415 const SymbolDatabase* symbolDatabase = mTokenizer ->getSymbolDatabase ();
428- const std::size_t functions = symbolDatabase->functionScopes .size ();
429- for (std::size_t i = 0 ; i < functions; ++i) {
430- const Scope * scope = symbolDatabase->functionScopes [i];
416+ for (const Scope * scope : symbolDatabase->functionScopes ) {
431417 for (const Token* tok = scope->bodyStart ->next (); tok != scope->bodyEnd ; tok = tok->next ()) {
432418 if (!Token::Match (tok, " sprintf|snprintf|swprintf (" ))
433419 continue ;
0 commit comments