setVarId: Fixed bug (variable id for struct member not correctly set)
This commit is contained in:
parent
e42953bd3b
commit
2e77f3bf04
|
@ -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() == ".");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue