stringLiteralWrite: only check in function scopes

This commit is contained in:
Daniel Marjamäki 2015-05-10 10:34:13 +02:00
parent 96891dface
commit 075b07fb6c
1 changed files with 15 additions and 10 deletions

View File

@ -34,16 +34,21 @@ namespace {
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckString::stringLiteralWrite() void CheckString::stringLiteralWrite()
{ {
for (const Token* tok = _tokenizer->tokens(); tok; tok = tok->next()) { const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
if (!tok->variable() || !tok->variable()->isPointer()) const std::size_t functions = symbolDatabase->functionScopes.size();
continue; for (std::size_t i = 0; i < functions; ++i) {
const Token *str = tok->getValueTokenMinStrSize(); const Scope * scope = symbolDatabase->functionScopes[i];
if (!str) for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
continue; if (!tok->variable() || !tok->variable()->isPointer())
if (Token::Match(tok, "%var% [") && Token::simpleMatch(tok->linkAt(1), "] =")) continue;
stringLiteralWriteError(tok); const Token *str = tok->getValueTokenMinStrSize();
else if (Token::Match(tok->previous(), "* %var% =")) if (!str)
stringLiteralWriteError(tok); continue;
if (Token::Match(tok, "%var% [") && Token::simpleMatch(tok->linkAt(1), "] ="))
stringLiteralWriteError(tok);
else if (Token::Match(tok->previous(), "* %var% ="))
stringLiteralWriteError(tok);
}
} }
} }