Extended Message "fflushOnInputStream" to files opened for reading.
This commit is contained in:
parent
b07f61170d
commit
288c94a47f
|
@ -176,12 +176,20 @@ void CheckIO::checkFileUsage()
|
|||
operation = Filepointer::OPEN;
|
||||
} else if ((tok->str() == "rewind" || tok->str() == "fseek" || tok->str() == "fsetpos" || tok->str() == "fflush") ||
|
||||
(windows && tok->str() == "_fseeki64")) {
|
||||
if (_settings->isEnabled("portability") && Token::simpleMatch(tok, "fflush ( stdin )"))
|
||||
fflushOnInputStreamError(tok, tok->strAt(2));
|
||||
if (_settings->isEnabled("portability") && tok->str() == "fflush") {
|
||||
fileTok = tok->tokAt(2);
|
||||
|
||||
if (fileTok && fileTok->str() == "stdin")
|
||||
fflushOnInputStreamError(tok, fileTok->str());
|
||||
else {
|
||||
Filepointer& f = filepointers[fileTok->varId()];
|
||||
if (f.mode == READ_MODE)
|
||||
fflushOnInputStreamError(tok, fileTok->str());
|
||||
}
|
||||
}
|
||||
|
||||
fileTok = tok->tokAt(2);
|
||||
operation = Filepointer::POSITIONING;
|
||||
}
|
||||
} else if (tok->str() == "fgetc" || tok->str() == "fgetwc" ||
|
||||
tok->str() == "fgets" || tok->str() == "fgetws" || tok->str() == "fread" ||
|
||||
tok->str() == "fscanf" || tok->str() == "fwscanf" || tok->str() == "getc" ||
|
||||
|
|
|
@ -589,6 +589,23 @@ private:
|
|||
" fflush(stdout);\n"
|
||||
"}", false, true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo(FILE*& f) {\n"
|
||||
" f = fopen(path, \"r\");\n"
|
||||
" fflush(f);\n"
|
||||
"}", false, true);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (portability) fflush() called on input stream 'f' may result in undefined behaviour on non-linux systems.\n", errout.str());
|
||||
|
||||
check("void foo(FILE*& f) {\n"
|
||||
" f = fopen(path, \"w\");\n"
|
||||
" fflush(f);\n"
|
||||
"}", false, true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo(FILE*& f) {\n"
|
||||
" fflush(f);\n"
|
||||
"}", false, true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue