Fixed #959: (new check: wrong usage of fflush()) Simplified and set severity to error
This commit is contained in:
parent
c8c5f95721
commit
21b7eb61f5
|
@ -259,12 +259,11 @@ void CheckOther::checkEmptyStringTest()
|
|||
//---------------------------------------------------------------------------
|
||||
void CheckOther::checkFflushOnInputStream()
|
||||
{
|
||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
||||
const Token *tok = _tokenizer->tokens();
|
||||
while (tok && (tok = Token::findmatch(tok, "fflush ( stdin )")))
|
||||
{
|
||||
if (Token::Match(tok, "fflush ( stdin )"))
|
||||
{
|
||||
fflushOnInputStreamError(tok, tok->strAt(2));
|
||||
}
|
||||
fflushOnInputStreamError(tok, tok->strAt(2));
|
||||
tok = tok->tokAt(4);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3615,6 +3614,6 @@ void CheckOther::emptyStringTestError(const Token *tok, const std::string &var_n
|
|||
|
||||
void CheckOther::fflushOnInputStreamError(const Token *tok, const std::string &varname)
|
||||
{
|
||||
reportError(tok, Severity::possibleError,
|
||||
reportError(tok, Severity::error,
|
||||
"fflushOnInputStream", "fflush() called on input stream \"" + varname + "\" may result in undefined behaviour");
|
||||
}
|
||||
|
|
|
@ -237,8 +237,6 @@ public:
|
|||
"* division with zero\n"
|
||||
"* null pointer dereferencing\n"
|
||||
"* using uninitialized variables and data\n"
|
||||
|
||||
// possible error
|
||||
"* using fflush() on an input stream\n"
|
||||
|
||||
// style
|
||||
|
|
|
@ -2481,7 +2481,7 @@ private:
|
|||
"{\n"
|
||||
" fflush(stdin);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (possible error) fflush() called on input stream \"stdin\" may result in undefined behaviour\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) fflush() called on input stream \"stdin\" may result in undefined behaviour\n", errout.str());
|
||||
|
||||
check("void foo()\n"
|
||||
"{\n"
|
||||
|
|
Loading…
Reference in New Issue