Fixed regression #4368.

This commit is contained in:
PKEuS 2012-12-08 00:26:10 -08:00
parent 0f1e150386
commit 578e582987
2 changed files with 42 additions and 0 deletions

View File

@ -255,6 +255,11 @@ void CheckIO::checkFileUsage()
}
}
}
for (std::map<unsigned int, Filepointer>::iterator i = filepointers.begin(); i != filepointers.end(); ++i) {
i->second.op_indent = 0;
i->second.mode = UNKNOWN;
i->second.lastOperation = Filepointer::UNKNOWN_OP;
}
}
}

View File

@ -287,6 +287,43 @@ private:
" fclose(f[0]);\n"
"}");
ASSERT_EQUALS("", errout.str());
// #4368: multiple functions
check("static FILE *fp = NULL;\n"
"\n"
"void close()\n"
"{\n"
" fclose(fp);\n"
"}\n"
"\n"
"void dump()\n"
"{\n"
" if (fp == NULL) return;\n"
" fprintf(fp, \"Here's the output.\\n\");\n"
"}\n"
"\n"
"int main()\n"
"{\n"
" fp = fopen(\"test.txt\", \"w\");\n"
" dump();\n"
" close();\n"
" return 0;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("static FILE *fp = NULL;\n"
"\n"
"void close()\n"
"{\n"
" fclose(fp);\n"
"}\n"
"\n"
"void dump()\n"
"{\n"
" fclose(fp);\n"
" fprintf(fp, \"Here's the output.\\n\");\n"
"}");
ASSERT_EQUALS("[test.cpp:11]: (error) Used file that is not opened.\n", errout.str());
}
void fileIOwithoutPositioning() {