Fixed #1364 (False positive: (error) Possible null pointer dereference)

This commit is contained in:
Daniel Marjamäki 2010-02-08 18:25:08 +01:00
parent 19589adc1d
commit 8853f304af
3 changed files with 10 additions and 6 deletions

View File

@ -4482,7 +4482,10 @@ bool Tokenizer::simplifyKnownVariables()
break;
// Using the variable in condition..
if (Token::Match(tok3, "(|!|==|!=|<|<=|>|>= %varid% )|==|!=|<|<=|>|>=", varid))
if (Token::Match(tok3->previous(), "if ( %varid% ==|!=|<|<=|>|>=|)", varid) ||
Token::Match(tok3, "( %varid% ==|!=|<|<=|>|>=", varid) ||
Token::Match(tok3, "!|==|!=|<|<=|>|>= %varid% ==|!=|<|<=|>|>=|)", varid) ||
Token::Match(tok3->previous(), "strlen|free ( %varid% )", varid))
{
tok3 = tok3->next();
tok3->str(value);

View File

@ -3268,14 +3268,14 @@ private:
"{\n"
" char buf[100];\n"
" char *p = buf;\n"
" x(p);\n"
" free(p);\n"
"}\n";
const char expected[] = "void f ( ) "
"{ "
"char buf [ 100 ] ; "
"; ; "
"x ( buf ) ; "
"free ( buf ) ; "
"}";
ASSERT_EQUALS(expected, tok(code));

View File

@ -786,8 +786,9 @@ private:
" if ( g(a));\n"
"}\n";
// TODO: if a is passed by value is is ok to simplify..
ASSERT_EQUALS(
"void f ( ) { int a ; a = 4 ; if ( g ( 4 ) ) { ; } }",
"void f ( ) { int a ; a = 4 ; if ( g ( a ) ) { ; } }",
simplifyKnownVariables(code));
}
@ -911,11 +912,11 @@ private:
" {\n"
" }\n"
"\n"
" a(b);\n"
" return b;\n"
"}\n";
ASSERT_EQUALS(
"void f ( ) { int b ; b = 0 ; b = 1 ; for ( int i = 0 ; i < 10 ; i ++ ) { } a ( 1 ) ; }",
"void f ( ) { int b ; b = 0 ; b = 1 ; for ( int i = 0 ; i < 10 ; i ++ ) { } return 1 ; }",
simplifyKnownVariables(code));
}
}