sprintf: fixed bug "false positive when variable is used again after snprintf"
This commit is contained in:
parent
0c3c00daec
commit
8c4260519c
|
@ -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() == "(")
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue