fixed snprintf false positive (#210)

This commit is contained in:
Daniel Marjamäki 2009-03-24 18:43:39 +01:00
parent 65070cc067
commit 6580e0eb21
2 changed files with 12 additions and 1 deletions

View File

@ -314,7 +314,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
} }
// snprintf.. // 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)); int n = std::atoi(tok->strAt(4));
if (n > size) if (n > size)

View File

@ -91,6 +91,7 @@ private:
TEST_CASE(snprintf1); TEST_CASE(snprintf1);
TEST_CASE(snprintf2); TEST_CASE(snprintf2);
TEST_CASE(snprintf3); TEST_CASE(snprintf3);
TEST_CASE(snprintf4);
TEST_CASE(strncat1); TEST_CASE(strncat1);
TEST_CASE(strncat2); TEST_CASE(strncat2);
@ -470,6 +471,16 @@ private:
ASSERT_EQUALS(std::string(""), errout.str()); 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());
}