From 075b07fb6c911ec0e98fec43b7a3e9118a742cd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 10 May 2015 10:34:13 +0200 Subject: [PATCH] stringLiteralWrite: only check in function scopes --- lib/checkstring.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/checkstring.cpp b/lib/checkstring.cpp index 74cd99d43..6c34b2e91 100644 --- a/lib/checkstring.cpp +++ b/lib/checkstring.cpp @@ -34,16 +34,21 @@ namespace { //--------------------------------------------------------------------------- void CheckString::stringLiteralWrite() { - for (const Token* tok = _tokenizer->tokens(); tok; tok = tok->next()) { - if (!tok->variable() || !tok->variable()->isPointer()) - continue; - const Token *str = tok->getValueTokenMinStrSize(); - if (!str) - continue; - if (Token::Match(tok, "%var% [") && Token::simpleMatch(tok->linkAt(1), "] =")) - stringLiteralWriteError(tok); - else if (Token::Match(tok->previous(), "* %var% =")) - stringLiteralWriteError(tok); + const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); + const std::size_t functions = symbolDatabase->functionScopes.size(); + for (std::size_t i = 0; i < functions; ++i) { + const Scope * scope = symbolDatabase->functionScopes[i]; + for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + if (!tok->variable() || !tok->variable()->isPointer()) + continue; + const Token *str = tok->getValueTokenMinStrSize(); + if (!str) + continue; + if (Token::Match(tok, "%var% [") && Token::simpleMatch(tok->linkAt(1), "] =")) + stringLiteralWriteError(tok); + else if (Token::Match(tok->previous(), "* %var% =")) + stringLiteralWriteError(tok); + } } }