Skip to content

Commit 6d0c2f7

Browse files
committed
Fixed false positive useClosedFile when noreturn function is called (#7359)
1 parent 0e8777e commit 6d0c2f7

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

lib/checkio.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ void CheckIO::checkFileUsage()
148148
i->second.lastOperation = Filepointer::UNKNOWN_OP;
149149
}
150150
}
151-
} else if (tok->str() == "return" || tok->str() == "continue" || tok->str() == "break") { // Reset upon return, continue or break
151+
} else if (tok->str() == "return" || tok->str() == "continue" || tok->str() == "break" || _settings->library.isnoreturn(tok)) { // Reset upon return, continue or break
152152
for (std::map<unsigned int, Filepointer>::iterator i = filepointers.begin(); i != filepointers.end(); ++i) {
153153
i->second.mode_indent = 0;
154154
i->second.mode = UNKNOWN_OM;

test/testio.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,18 @@ class TestIO : public TestFixture {
480480
"}");
481481
ASSERT_EQUALS("", errout.str());
482482

483+
check("void chdcd_parse_nero(FILE *infile) {\n"
484+
" switch (mode) {\n"
485+
" case 0x0300:\n"
486+
" fclose(infile);\n"
487+
" exit(0);\n"
488+
" case 0x0500:\n"
489+
" fclose(infile);\n"
490+
" return;\n"
491+
" }\n"
492+
"}");
493+
ASSERT_EQUALS("", errout.str());
494+
483495
// #4649
484496
check("void foo() {\n"
485497
" struct {FILE *f1; FILE *f2;} a;\n"

0 commit comments

Comments
 (0)