Fix FP with fclose after comma (#7525) (#1407)

This commit is contained in:
rikardfalkeborn 2018-10-01 11:58:27 +02:00 committed by Daniel Marjamäki
parent 3a186b5bff
commit b3fef7957a
2 changed files with 12 additions and 1 deletions

View File

@ -919,7 +919,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
}
}
if (Token::Match(tok->previous(), "%op%|;|{|}|) ::| %name%") || (Token::Match(tok->previous(), "( ::| %name%") && (!rettail || rettail->str() != "loop"))) {
if (Token::Match(tok->previous(), "%op%|;|,|{|}|) ::| %name%") || (Token::Match(tok->previous(), "( ::| %name%") && (!rettail || rettail->str() != "loop"))) {
if (tok->str() == "::")
tok = tok->next();

View File

@ -347,6 +347,7 @@ private:
TEST_CASE(creat_function);
TEST_CASE(close_function);
TEST_CASE(fd_functions);
TEST_CASE(fclose_comma); // #7525
TEST_CASE(pointer_to_pointer);
TEST_CASE(dealloc_and_alloc_in_func);
@ -3816,6 +3817,16 @@ private:
}
}
void fclose_comma() {
check("int main(void) {\n"
" const char *const outfile = \"out.txt\";\n"
" FILE *f;\n"
" f = fopen(outfile, \"w\");\n"
" fprintf(f, \"foo\\n\"), fclose(f);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void pointer_to_pointer() {
check("void f(char **data)\n"
"{\n"