Fix #995 (false positive: buffer access out of bounds when using fgets)

http://sourceforge.net/apps/trac/cppcheck/ticket/995
This commit is contained in:
Reijo Tomperi 2009-11-21 15:45:52 +02:00
parent 6417704577
commit 9bdf4502ed
2 changed files with 3 additions and 3 deletions

View File

@ -482,7 +482,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const char *varname[], con
MathLib::isInt(tok->strAt(4)))
{
size_t len = MathLib::toLongNumber(tok->strAt(4));
if (len >= static_cast<size_t>(size))
if (len > static_cast<size_t>(size))
{
bufferOverrun(tok);
continue;

View File

@ -779,14 +779,14 @@ private:
check("void f()\n"
"{\n"
" char str[3];\n"
" fgets(str, 2, stdin);\n"
" fgets(str, 3, stdin);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("void f()\n"
"{\n"
" char str[3];\n"
" fgets(str, 3, stdin);\n"
" fgets(str, 4, stdin);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str());
}