diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 6f2c1b5af..33edb4558 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -639,9 +639,10 @@ void Tokenizer::setVarId() ++_varId; int indentlevel = 0; int parlevel = 0; + bool dot = false; for (tok2 = tok->next(); tok2; tok2 = tok2->next()) { - if (tok2->str() == varname) + if (!dot && tok2->str() == varname) tok2->varId(_varId); else if (tok2->str() == "{") ++indentlevel; @@ -657,6 +658,7 @@ void Tokenizer::setVarId() --parlevel; else if (parlevel < 0 && tok2->str() == ";") break; + dot = bool(tok2->str() == "."); } } } diff --git a/test/testother.cpp b/test/testother.cpp index f1032a92f..0ec1280d7 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -40,6 +40,7 @@ private: TEST_CASE(sprintf1); // Dangerous usage of sprintf TEST_CASE(sprintf2); TEST_CASE(sprintf3); + TEST_CASE(sprintf4); // struct member } void check(const char code[]) @@ -99,6 +100,8 @@ private: tokenizer.tokenize(istr, "test.cpp"); tokenizer.setVarId(); + //tokenizer.tokens()->printOut( "tokens" ); + // Clear the error buffer.. errout.str(""); @@ -138,6 +141,22 @@ private: ASSERT_EQUALS(std::string(""), errout.str()); } + void sprintf4() + { + sprintfUsage("struct A\n" + "{\n" + " char filename[128];\n" + "};\n" + "\n" + "void foo()\n" + "{\n" + " const char* filename = \"hello\";\n" + " struct A a;\n" + " snprintf(a.filename, 128, \"%s\", filename);\n" + "}\n"); + ASSERT_EQUALS(std::string(""), errout.str()); + } + }; REGISTER_TEST(TestOther)