From 740e790bf15a1f2cd26ece5b451b125e7708bbd3 Mon Sep 17 00:00:00 2001 From: kchrist Date: Fri, 15 Mar 2013 06:42:46 +0100 Subject: [PATCH] Fixed #4649 (false positive: Used file that is not opened; variables in struct) --- lib/checkio.cpp | 3 +++ test/testio.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/checkio.cpp b/lib/checkio.cpp index 35f1b313e..6a8475af7 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -205,6 +205,9 @@ void CheckIO::checkFileUsage() } } + while (Token::Match(fileTok, "%var% .")) + fileTok = fileTok->tokAt(2); + if (!fileTok || !fileTok->varId()) continue; diff --git a/test/testio.cpp b/test/testio.cpp index 201e1946a..aeac6ba41 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -338,6 +338,16 @@ private: " }\n" "}"); ASSERT_EQUALS("", errout.str()); + + // #4649 + check("void foo() {\n" + " struct {FILE *f1; FILE *f2;} a;\n" + " a.f1 = fopen(name,mode);\n" + " a.f2 = fopen(name,mode);\n" + " fclose(a.f1);\n" + " fclose(a.f2);\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void fileIOwithoutPositioning() {