better description for the message with id strncatUsage

This commit is contained in:
Daniel Marjamäki 2009-07-11 12:16:38 +02:00
parent 59372199e3
commit 36896e1ca0
2 changed files with 4 additions and 4 deletions

View File

@ -62,7 +62,7 @@ void CheckBufferOverrunClass::bufferOverrun(const Token *tok)
void CheckBufferOverrunClass::strncatUsage(const Token *tok)
{
reportError(tok, "all", "strncatUsage", "Dangerous usage of strncat, possible buffer overrun");
reportError(tok, "all", "strncatUsage", "Dangerous usage of strncat. Tip: the 3rd parameter means maximum number of characters to append");
}
void CheckBufferOverrunClass::outOfBounds(const Token *tok, const std::string &what)
@ -290,7 +290,7 @@ void CheckBufferOverrunClass::checkScope(const Token *tok, const char *varname[]
if (varid > 0 && Token::Match(tok, "strncat ( %varid% , %any% , %num% )", varid))
{
int n = atoi(tok->strAt(6));
if (n == size)
if (n >= (size - 1))
strncatUsage(tok);
}

View File

@ -555,7 +555,7 @@ private:
" strncpy(str, a, 10);\n"
" strncat(str, b, 10);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (all) Dangerous usage of strncat, possible buffer overrun\n", errout.str());
ASSERT_EQUALS("[test.cpp:5]: (all) Dangerous usage of strncat. Tip: the 3rd parameter means maximum number of characters to append\n", errout.str());
}
void strncat2()
@ -565,7 +565,7 @@ private:
" char str[5];\n"
" strncat(str, a, 5);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (all) Dangerous usage of strncat, possible buffer overrun\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (all) Dangerous usage of strncat. Tip: the 3rd parameter means maximum number of characters to append\n", errout.str());
}