Fixed #1717 (False positive: Resource leak with while)

This commit is contained in:
Daniel Marjamäki 2010-05-30 13:15:15 +02:00
parent 83c62eca9c
commit 08b6e6ee09
2 changed files with 16 additions and 1 deletions

View File

@ -3590,6 +3590,7 @@ bool Tokenizer::simplifyTokenList()
simplifyFunctionParameters(); simplifyFunctionParameters();
elseif(); elseif();
simplifyErrNoInWhile();
simplifyIfAssign(); simplifyIfAssign();
simplifyRedundantParanthesis(); simplifyRedundantParanthesis();
simplifyIfNot(); simplifyIfNot();
@ -3598,7 +3599,6 @@ bool Tokenizer::simplifyTokenList()
simplifyComparisonOrder(); simplifyComparisonOrder();
simplifyNestedStrcat(); simplifyNestedStrcat();
simplifyWhile0(); simplifyWhile0();
simplifyErrNoInWhile();
simplifyFuncInWhile(); simplifyFuncInWhile();
simplifyIfAssign(); // could be affected by simplifyIfNot simplifyIfAssign(); // could be affected by simplifyIfNot

View File

@ -37,6 +37,12 @@ private:
void run() void run()
{ {
// Make sure the Tokenizer::simplifyTokenList works.
// The order of the simplifications is important. So this test
// case shall make sure the simplifications are done in the
// correct order
TEST_CASE(simplifyTokenList1);
TEST_CASE(cast); TEST_CASE(cast);
TEST_CASE(iftruefalse); TEST_CASE(iftruefalse);
TEST_CASE(combine_strings); TEST_CASE(combine_strings);
@ -297,6 +303,15 @@ private:
return ret; return ret;
} }
void simplifyTokenList1()
{
// #1717 : The simplifyErrNoInWhile needs to be used before simplifyIfAssign..
ASSERT_EQUALS("; x = f ( ) ; while ( ( x ) == -1 ) { x = f ( ) ; }",
tok(";while((x=f())==-1 && errno==EINTR){}",true));
}
void cast() void cast()
{ {
ASSERT_EQUALS("if ( ! p )", tok("if (p == (char *)0)")); ASSERT_EQUALS("if ( ! p )", tok("if (p == (char *)0)"));