Fixed #3922 (false positive: (error) null pointer dereference)
This commit is contained in:
parent
6a5cc4727d
commit
7786e12ba2
|
@ -3395,6 +3395,8 @@ bool Tokenizer::simplifyTokenList()
|
||||||
modified |= simplifyCalculations();
|
modified |= simplifyCalculations();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
simplifyConditionOperator();
|
||||||
|
|
||||||
// replace strlen(str)
|
// replace strlen(str)
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
if (Token::Match(tok, "strlen ( %str% )")) {
|
if (Token::Match(tok, "strlen ( %str% )")) {
|
||||||
|
@ -4144,6 +4146,28 @@ void Tokenizer::simplifyCompoundAssignment()
|
||||||
void Tokenizer::simplifyConditionOperator()
|
void Tokenizer::simplifyConditionOperator()
|
||||||
{
|
{
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
|
if (Token::Match(tok,"return|= ( true|false ) ?")) {
|
||||||
|
Token *tok2 = tok->tokAt(5);
|
||||||
|
while (tok2 && (tok2->isName() || tok2->isNumber() || tok2->isArithmeticalOp()))
|
||||||
|
tok2 = tok2->next();
|
||||||
|
if (tok2 && tok2->str() == ":") {
|
||||||
|
if (tok->strAt(2) == "false") {
|
||||||
|
Token::eraseTokens(tok,tok2->next());
|
||||||
|
} else {
|
||||||
|
Token *tok3 = tok2->next();
|
||||||
|
while (tok3 && (tok3->isName() || tok3->isNumber() || tok3->isArithmeticalOp()))
|
||||||
|
tok3 = tok3->next();
|
||||||
|
|
||||||
|
if (tok3 && tok3->str() == ";") {
|
||||||
|
tok->deleteNext(4);
|
||||||
|
tok = tok2;
|
||||||
|
while (tok && tok->str() != ";")
|
||||||
|
tok->deleteThis();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (tok->str() == "(")
|
if (tok->str() == "(")
|
||||||
tok = tok->link();
|
tok = tok->link();
|
||||||
else if (tok->str() == ")")
|
else if (tok->str() == ")")
|
||||||
|
|
|
@ -2792,6 +2792,15 @@ private:
|
||||||
"1: ; char * p@1 ; if ( a ) { * p@1 = 1 ; } else { * p@1 = 0 ; }\n";
|
"1: ; char * p@1 ; if ( a ) { * p@1 = 1 ; } else { * p@1 = 0 ; }\n";
|
||||||
ASSERT_EQUALS(expected, tokenizeDebugListing(code, true));
|
ASSERT_EQUALS(expected, tokenizeDebugListing(code, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// #3922 - (true)
|
||||||
|
ASSERT_EQUALS("; x = 2 ;", tok("; x = (true)?2:4;"));
|
||||||
|
ASSERT_EQUALS("; x = 4 ;", tok("; x = (false)?2:4;"));
|
||||||
|
ASSERT_EQUALS("; x = * a ;", tok("; x = (true)?*a:*b;"));
|
||||||
|
ASSERT_EQUALS("; x = * b ;", tok("; x = (false)?*a:*b;"));
|
||||||
|
ASSERT_EQUALS("void f ( ) { return 1 ; }", tok("void f() { char *p=0; return (p==0)?1:2; }"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void calculations() {
|
void calculations() {
|
||||||
|
|
Loading…
Reference in New Issue