2121// ---------------------------------------------------------------------------
2222
2323#include " checknonreentrantfunctions.h"
24+ #include " symboldatabase.h"
2425
2526// ---------------------------------------------------------------------------
2627
@@ -35,30 +36,34 @@ void CheckNonReentrantFunctions::nonReentrantFunctions()
3536 if (!_settings->standards .posix || !_settings->isEnabled (" portability" ))
3637 return ;
3738
38- std::map<std::string,std::string>::const_iterator nonReentrant_end = _nonReentrantFunctions.end ();
39- for (const Token *tok = _tokenizer->tokens (); tok; tok = tok->next ()) {
40- // Look for function invocations
41- if (!tok->isName () || tok->strAt (1 ) != " (" || tok->varId () != 0 )
42- continue ;
43-
44- // Check for non-reentrant function name
45- std::map<std::string,std::string>::const_iterator it = _nonReentrantFunctions.find (tok->str ());
46- if (it == nonReentrant_end)
47- continue ;
48-
49- const Token *prev = tok->previous ();
50- if (prev) {
51- // Ignore function definitions, class members or class definitions
52- if (prev->isName () || Token::Match (prev, " .|:" ))
39+ const SymbolDatabase * const symbolDatabase = _tokenizer->getSymbolDatabase ();
40+ const std::size_t functions = symbolDatabase->functionScopes .size ();
41+ for (std::size_t i = 0 ; i < functions; ++i) {
42+ const Scope * scope = symbolDatabase->functionScopes [i];
43+ for (const Token *tok = scope->classStart ->next (); tok != scope->classEnd ; tok = tok->next ()) {
44+ // Look for function invocations
45+ if (tok->varId () != 0 || !tok->isName () || tok->strAt (1 ) != " (" )
5346 continue ;
5447
55- // Check for "std" or global namespace, ignore other namespaces
56- if (prev->str () == " ::" && prev->previous () && prev->previous ()->str () != " std" && prev->previous ()->isName ())
48+ // Check for non-reentrant function name
49+ std::map<std::string, std::string>::const_iterator it = _nonReentrantFunctions.find (tok->str ());
50+ if (it == _nonReentrantFunctions.end ())
5751 continue ;
58- }
5952
60- // Only affecting multi threaded code, therefore this is "portability"
61- reportError (tok, Severity::portability, " nonreentrantFunctions" +it->first , it->second );
53+ const Token *prev = tok->previous ();
54+ if (prev) {
55+ // Ignore function definitions, class members or class definitions
56+ if (prev->str () == " ." )
57+ continue ;
58+
59+ // Check for "std" or global namespace, ignore other namespaces
60+ if (prev->str () == " ::" && prev->previous () && prev->previous ()->str () != " std" && prev->previous ()->isName ())
61+ continue ;
62+ }
63+
64+ // Only affecting multi threaded code, therefore this is "portability"
65+ reportError (tok, Severity::portability, " nonreentrantFunctions" + it->first , it->second );
66+ }
6267 }
6368}
6469// ---------------------------------------------------------------------------
0 commit comments