sprintf: fixed bug "false positive when variable is used again after snprintf"

This commit is contained in:
Daniel Marjamäki 2009-01-10 14:27:31 +00:00
parent 0c3c00daec
commit 8c4260519c
2 changed files with 14 additions and 1 deletions

View File

@ -344,7 +344,7 @@ void CheckOther::InvalidFunctionUsage()
tok2 = tok2->next();
// is any source buffer overlapping the target buffer?
unsigned int parlevel = 0;
int parlevel = 0;
while ((tok2 = tok2->next()) != NULL)
{
if (tok2->str() == "(")

View File

@ -39,6 +39,7 @@ private:
TEST_CASE(sprintf1); // Dangerous usage of sprintf
TEST_CASE(sprintf2);
TEST_CASE(sprintf3);
}
void check(const char code[])
@ -125,6 +126,18 @@ private:
"}\n");
ASSERT_EQUALS(std::string(""), errout.str());
}
void sprintf3()
{
sprintfUsage("void foo()\n"
"{\n"
" char buf[100];\n"
" sprintf(buf,\"%i\",sizeof(buf));\n"
" if (buf[0]);\n"
"}\n");
ASSERT_EQUALS(std::string(""), errout.str());
}
};
REGISTER_TEST(TestOther)