@@ -1162,13 +1162,14 @@ void CppCheck::executeRules(const std::string &tokenlist, const TokenList &list)
11621162 return ;
11631163
11641164 // Write all tokens in a string that can be parsed by pcre
1165- std::ostringstream ostr;
1166- for (const Token *tok = list.front (); tok; tok = tok->next ())
1167- ostr << " " << tok->str ();
1168- const std::string str (ostr.str ());
1165+ std::string str;
1166+ for (const Token *tok = list.front (); tok; tok = tok->next ()) {
1167+ str += " " ;
1168+ str += tok->str ();
1169+ }
11691170
11701171 for (const Settings::Rule &rule : mSettings .rules ) {
1171- if (rule.pattern . empty () || rule. id .empty () || rule.severity == Severity::none || rule.tokenlist != tokenlist)
1172+ if (rule.id .empty () || rule.severity == Severity::none || rule.tokenlist != tokenlist)
11721173 continue ;
11731174
11741175 if (!mSettings .quiet ) {
@@ -1177,28 +1178,30 @@ void CppCheck::executeRules(const std::string &tokenlist, const TokenList &list)
11771178
11781179 auto f = [&](int pos1, int pos2) {
11791180 // determine location..
1180- std::string file = list. getSourceFilePath () ;
1181+ int fileIndex = 0 ;
11811182 int line = 0 ;
11821183
11831184 std::size_t len = 0 ;
11841185 for (const Token *tok = list.front (); tok; tok = tok->next ()) {
11851186 len = len + 1U + tok->str ().size ();
11861187 if (len > pos1) {
1187- file = list. getFiles (). at ( tok->fileIndex () );
1188+ fileIndex = tok->fileIndex ();
11881189 line = tok->linenr ();
11891190 break ;
11901191 }
11911192 }
11921193
1194+ const std::string& file = list.getFiles ()[fileIndex];
1195+
11931196 ErrorMessage::FileLocation loc (file, line, 0 );
11941197
11951198 // Create error message
1196- std::string summary;
1197- if (rule. summary . empty ())
1198- summary = " found ' " + str. substr (pos1, pos2 - pos1) + " ' " ;
1199- else
1200- summary = rule.summary ;
1201- const ErrorMessage errmsg ({ std::move (loc)}, list. getSourceFilePath (), rule. severity , summary, rule. id , Certainty::normal);
1199+ const ErrorMessage errmsg ({ std::move (loc)},
1200+ list. getSourceFilePath (),
1201+ rule. severity ,
1202+ !rule. summary . empty () ? rule. summary : " found ' " + str. substr (pos1, pos2 - pos1) + " ' " ,
1203+ rule.id ,
1204+ Certainty::normal);
12021205
12031206 // Report error
12041207 reportErr (errmsg);
0 commit comments