fixed snprintf false positive (#210)
This commit is contained in:
parent
65070cc067
commit
6580e0eb21
|
@ -314,7 +314,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
|
|||
}
|
||||
|
||||
// snprintf..
|
||||
if (varid > 0 && Token::Match(tok, "snprintf ( %varid% , %num%", varid))
|
||||
if (varid > 0 && Token::Match(tok, "snprintf ( %varid% , %num% ,", varid))
|
||||
{
|
||||
int n = std::atoi(tok->strAt(4));
|
||||
if (n > size)
|
||||
|
|
|
@ -91,6 +91,7 @@ private:
|
|||
TEST_CASE(snprintf1);
|
||||
TEST_CASE(snprintf2);
|
||||
TEST_CASE(snprintf3);
|
||||
TEST_CASE(snprintf4);
|
||||
|
||||
TEST_CASE(strncat1);
|
||||
TEST_CASE(strncat2);
|
||||
|
@ -470,6 +471,16 @@ private:
|
|||
ASSERT_EQUALS(std::string(""), errout.str());
|
||||
}
|
||||
|
||||
void snprintf4()
|
||||
{
|
||||
check("void f(int x)\n"
|
||||
"{\n"
|
||||
" char str[5];\n"
|
||||
" snprintf(str, 8 - x, \"abcdefghijkl\");\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS(std::string(""), errout.str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue