Fixed #1364 (False positive: (error) Possible null pointer dereference)
This commit is contained in:
parent
19589adc1d
commit
8853f304af
|
@ -4482,7 +4482,10 @@ bool Tokenizer::simplifyKnownVariables()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Using the variable in condition..
|
// 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 = tok3->next();
|
||||||
tok3->str(value);
|
tok3->str(value);
|
||||||
|
|
|
@ -3268,14 +3268,14 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" char buf[100];\n"
|
" char buf[100];\n"
|
||||||
" char *p = buf;\n"
|
" char *p = buf;\n"
|
||||||
" x(p);\n"
|
" free(p);\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
const char expected[] = "void f ( ) "
|
const char expected[] = "void f ( ) "
|
||||||
"{ "
|
"{ "
|
||||||
"char buf [ 100 ] ; "
|
"char buf [ 100 ] ; "
|
||||||
"; ; "
|
"; ; "
|
||||||
"x ( buf ) ; "
|
"free ( buf ) ; "
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
ASSERT_EQUALS(expected, tok(code));
|
ASSERT_EQUALS(expected, tok(code));
|
||||||
|
|
|
@ -786,8 +786,9 @@ private:
|
||||||
" if ( g(a));\n"
|
" if ( g(a));\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
|
// TODO: if a is passed by value is is ok to simplify..
|
||||||
ASSERT_EQUALS(
|
ASSERT_EQUALS(
|
||||||
"void f ( ) { int a ; a = 4 ; if ( g ( 4 ) ) { ; } }",
|
"void f ( ) { int a ; a = 4 ; if ( g ( a ) ) { ; } }",
|
||||||
simplifyKnownVariables(code));
|
simplifyKnownVariables(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -911,11 +912,11 @@ private:
|
||||||
" {\n"
|
" {\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"\n"
|
"\n"
|
||||||
" a(b);\n"
|
" return b;\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
ASSERT_EQUALS(
|
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));
|
simplifyKnownVariables(code));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue