@@ -300,29 +300,27 @@ void ExecutionPath::checkScope(const Token *tok, std::list<ExecutionPath *> &che
300300 // bailout used variables in '; FOREACH ( .. ) { .. }'
301301 else if (tok->str () != " if" && Token::Match (tok->previous (), " [;{}] %var% (" )) {
302302 // goto {
303- const Token *tok2 = tok->next ()->link ();
304- if (tok2 && tok2->str () == " )" ) {
305- tok2 = tok2->next ();
306- if (tok2 && tok2->str () == " {" ) {
307- // goto "}"
308- tok2 = tok2->link ();
309-
310- // bail out all variables used in "{ .. }"
311- for (; tok && tok != tok2; tok = tok->next ()) {
312- if (tok->varId ())
313- ExecutionPath::bailOutVar (checks, tok->varId ());
314- }
303+ const Token *tok2 = tok->next ()->link ()->next ();
304+ if (tok2 && tok2->str () == " {" ) {
305+ // goto "}"
306+ tok2 = tok2->link ();
307+
308+ // bail out all variables used in "{ .. }"
309+ for (; tok && tok != tok2; tok = tok->next ()) {
310+ if (tok->varId ())
311+ ExecutionPath::bailOutVar (checks, tok->varId ());
315312 }
316313 }
317314 }
318315
319316 // .. ) { ... } => bail out
320- if (Token::simpleMatch ( tok, " ) { " ) ) {
317+ if (tok-> str () == " ) " && tok-> next () && tok-> next ()-> str () == " { " ) {
321318 ExecutionPath::bailOut (checks);
322319 return ;
323320 }
324321
325- if (Token::Match (tok, " abort|exit (" )) {
322+ if ((tok->str () == " abort" || tok->str () == " exit" ) &&
323+ tok->next () && tok->next ()->str () == " (" ) {
326324 ExecutionPath::bailOut (checks);
327325 return ;
328326 }
@@ -360,12 +358,12 @@ void ExecutionPath::checkScope(const Token *tok, std::list<ExecutionPath *> &che
360358 continue ;
361359 }
362360
363- if (tok->str () == " if" ) {
361+ if (tok->str () == " if" && tok-> next () && tok-> next ()-> str () == " ( " ) {
364362 // what variable ids should the numberOfIf be counted for?
365363 std::set<unsigned int > countif;
366364
367365 std::list<ExecutionPath *> newchecks;
368- while (tok->str () == " if" ) {
366+ while (tok->str () == " if" && tok-> next () && tok-> next ()-> str () == " ( " ) {
369367 // goto "("
370368 tok = tok->next ();
371369
@@ -377,12 +375,12 @@ void ExecutionPath::checkScope(const Token *tok, std::list<ExecutionPath *> &che
377375 }
378376
379377 // goto ")"
380- tok = tok ? tok ->link () : 0 ;
378+ tok = tok->link ();
381379
382380 // goto "{"
383- tok = tok ? tok ->next () : 0 ;
381+ tok = tok->next ();
384382
385- if (!Token::simpleMatch ( tok, " {" ) ) {
383+ if (!tok || tok-> str () != " {" ) {
386384 ExecutionPath::bailOut (checks);
387385 ExecutionPath::bailOut (newchecks);
388386 return ;
@@ -395,12 +393,12 @@ void ExecutionPath::checkScope(const Token *tok, std::list<ExecutionPath *> &che
395393 tok = tok->link ();
396394
397395 // there is no else => break out
398- if (Token::Match ( tok, " } !! else" ) )
396+ if (! tok-> next () || tok-> next ()-> str () != " else" )
399397 break ;
400398
401399 // parse next "if"..
402400 tok = tok->tokAt (2 );
403- if (tok->str () == " if" )
401+ if (tok && tok ->str () == " if" )
404402 continue ;
405403
406404 // there is no "if"..
0 commit comments