Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/checkleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
varInfo2.erase(tok->tokAt(2)->varId());
} else if (Token::Match(tok->next(), "( 0 < %var% )|&&")) {
varInfo2.erase(tok->tokAt(4)->varId());
} else if (Token::Match(tok->next(), "( %var% == -1 )|&&")) {
varInfo1.erase(tok->tokAt(2)->varId());
} else if (Token::Match(tok->next(), "( -1 == %var% )|&&")) {
varInfo1.erase(tok->tokAt(4)->varId());
}

checkScope(tok2->next(), &varInfo1, notzero);
Expand Down
10 changes: 10 additions & 0 deletions test/testleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class TestLeakAutoVar : public TestFixture {
TEST_CASE(ifelse5);
TEST_CASE(ifelse6); // #3370
TEST_CASE(ifelse7); // #5576 - if (fd < 0)
TEST_CASE(ifelse8); // #5747 - if (fd == -1)

// switch
TEST_CASE(switch1);
Expand Down Expand Up @@ -493,6 +494,15 @@ class TestLeakAutoVar : public TestFixture {
ASSERT_EQUALS("", errout.str());
}

void ifelse8() { // #5747
check("void f() {\n"
" int fd = socket(AF_INET, SOCK_PACKET, 0 );\n"
" if (fd == -1)\n"
" return;\n"
"}");
ASSERT_EQUALS("", errout.str());
}

void switch1() {
check("void f() {\n"
" char *p = 0;\n"
Expand Down