Fixed #3909: Handle constructor syntax initialization.
This commit is contained in:
parent
25b24d149f
commit
f5c42660de
|
@ -105,9 +105,12 @@ void CheckIO::checkFileUsage()
|
|||
if (!var || !var->varId() || !Token::Match(var->typeStartToken(), "FILE *"))
|
||||
continue;
|
||||
|
||||
if (var->isLocal())
|
||||
filepointers.insert(std::make_pair(var->varId(), Filepointer(CLOSED)));
|
||||
else {
|
||||
if (var->isLocal()) {
|
||||
if (var->nameToken()->strAt(1) == "(") // initialize by calling "ctor"
|
||||
filepointers.insert(std::make_pair(var->varId(), Filepointer(UNKNOWN)));
|
||||
else
|
||||
filepointers.insert(std::make_pair(var->varId(), Filepointer(CLOSED)));
|
||||
} else {
|
||||
filepointers.insert(std::make_pair(var->varId(), Filepointer(UNKNOWN)));
|
||||
// TODO: If all fopen calls we find open the file in the same type, we can set Filepointer::mode
|
||||
}
|
||||
|
|
|
@ -265,6 +265,18 @@ private:
|
|||
" fwrite(buffer, 5, 6, f);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo() {\n"
|
||||
" FILE* f;\n"
|
||||
" fwrite(buffer, 5, 6, f);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Used file that is not opened.\n", errout.str());
|
||||
|
||||
check("void foo() {\n"
|
||||
" FILE* f(stdout);\n"
|
||||
" fwrite(buffer, 5, 6, f);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void fileIOwithoutPositioning() {
|
||||
|
|
Loading…
Reference in New Issue