ericsesterhenn: Fix #1028 (False positive resource leak)

This commit is contained in:
Daniel Marjamäki 2009-11-30 16:45:19 +01:00
parent ded2e68c2e
commit 153a13272c
3 changed files with 18 additions and 1 deletions

View File

@ -4728,6 +4728,14 @@ void Tokenizer::simplifyComparisonOrder()
else
tok->tokAt(2)->str("<=");
}
else if (Token::Match(tok, "( %num% ==|!= %var% )"))
{
if (!tok->next()->isName() && !tok->next()->isNumber())
continue;
const std::string op1(tok->strAt(1));
tok->next()->str(tok->strAt(3));
tok->tokAt(3)->str(op1);
}
}
}

View File

@ -2194,6 +2194,15 @@ private:
" close(fd);\n"
"}\n", true);
ASSERT_EQUALS("", errout.str());
check("void f(const char *path)\n"
"{\n"
" int fd = open(path, O_RDONLY);\n"
" if (-1 == fd)\n"
" return;\n"
" close(fd);\n"
"}\n", true);
ASSERT_EQUALS("", errout.str());
}
void creat_function()

View File

@ -439,7 +439,7 @@ private:
ASSERT_EQUALS("= p ;", tok("= (p);"));
ASSERT_EQUALS("if ( a < p ) { }", tok("if(a<(p)){}"));
ASSERT_EQUALS("void f ( ) { int p ; if ( p == -1 ) { } }", tok("void f(){int p; if((p)==-1){}}"));
ASSERT_EQUALS("void f ( ) { int p ; if ( -1 == p ) { } }", tok("void f(){int p; if(-1==(p)){}}"));
ASSERT_EQUALS("void f ( ) { int p ; if ( p == -1 ) { } }", tok("void f(){int p; if(-1==(p)){}}"));
ASSERT_EQUALS("void f ( ) { int p ; if ( p ) { } }", tok("void f(){int p; if((p)){}}"));
ASSERT_EQUALS("return p ;", tok("return (p);"));
ASSERT_EQUALS("void f ( ) { int * p ; if ( ! * p ) { } }", tok("void f(){int *p; if (*(p) == 0) {}}"));