From a0890ecd2c9ce06d5e9480b5047373660bbe7724 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Mon, 20 Jul 2015 22:40:19 +0200 Subject: [PATCH] Fixed false positive: Do not print useClosedFile on arrays (#6823) --- lib/checkio.cpp | 2 +- test/testio.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) 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() {