Fixed false positive: Do not print useClosedFile on arrays (#6823)
This commit is contained in:
parent
c987a99ac8
commit
a0890ecd2c
|
@ -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
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue