Fixed #2413 (fflush() with NULL argument is valid.)

This commit is contained in:
Daniel Marjamäki 2011-01-06 08:12:34 +01:00
parent 03a484554c
commit d1854e330b
2 changed files with 8 additions and 1 deletions

View File

@ -86,7 +86,7 @@ void CheckNullPointer::parseFunctionCall(const Token &tok, std::list<const Token
var.push_back(tok.tokAt(2)); var.push_back(tok.tokAt(2));
else if (value == 0 && Token::Match(&tok, "memchr|memcmp|memcpy|memmove|memset|strcpy|printf|sprintf|snprintf")) else if (value == 0 && Token::Match(&tok, "memchr|memcmp|memcpy|memmove|memset|strcpy|printf|sprintf|snprintf"))
var.push_back(tok.tokAt(2)); var.push_back(tok.tokAt(2));
else if (Token::simpleMatch(&tok, "fflush")) else if (value != 0 && Token::simpleMatch(&tok, "fflush"))
var.push_back(tok.tokAt(2)); var.push_back(tok.tokAt(2));
} }

View File

@ -821,6 +821,13 @@ private:
" strcpy(p, \"abcd\");\n" " strcpy(p, \"abcd\");\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Null pointer dereference\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (error) Null pointer dereference\n", errout.str());
// Ticket #2413 - it's ok to pass NULL to fflush
check("void foo() {\n"
" fflush(NULL);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
}; };