diff --git a/lib/checkio.cpp b/lib/checkio.cpp index 63d9477f8..c51038a65 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -251,7 +251,7 @@ void CheckIO::checkFileUsage() while (Token::Match(fileTok, "%name% .")) fileTok = fileTok->tokAt(2); - if (!fileTok || !fileTok->varId()) + if (!fileTok || !fileTok->varId() || fileTok->strAt(1) == "[") continue; if (filepointers.find(fileTok->varId()) == filepointers.end()) { // function call indicates: Its a File diff --git a/test/testio.cpp b/test/testio.cpp index 33b700a32..40069bb7e 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -495,6 +495,16 @@ private: " while (fclose(a)) {}\n" "}"); 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() {