Fixed false positive: Do not print useClosedFile on arrays (#6823)

This commit is contained in:
PKEuS 2015-07-20 22:40:19 +02:00
parent c987a99ac8
commit a0890ecd2c
2 changed files with 11 additions and 1 deletions

View File

@ -251,7 +251,7 @@ void CheckIO::checkFileUsage()
while (Token::Match(fileTok, "%name% .")) while (Token::Match(fileTok, "%name% ."))
fileTok = fileTok->tokAt(2); fileTok = fileTok->tokAt(2);
if (!fileTok || !fileTok->varId()) if (!fileTok || !fileTok->varId() || fileTok->strAt(1) == "[")
continue; continue;
if (filepointers.find(fileTok->varId()) == filepointers.end()) { // function call indicates: Its a File if (filepointers.find(fileTok->varId()) == filepointers.end()) { // function call indicates: Its a File

View File

@ -495,6 +495,16 @@ private:
" while (fclose(a)) {}\n" " while (fclose(a)) {}\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:3]: (error) Used file that is not opened.\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (error) Used file that is not opened.\n", errout.str());
// #6823
check("void foo() {\n"
" FILE f[2];\n"
" f[0] = fopen(\"1\", \"w\");\n"
" f[1] = fopen(\"2\", \"w\");\n"
" fclose(f[0]);\n"
" fclose(f[1]);\n"
"}");
ASSERT_EQUALS("", errout.str());
} }
void fileIOwithoutPositioning() { void fileIOwithoutPositioning() {