Fixed #7310 (ValueFlow: Value of NULL in function call)

This commit is contained in:
Daniel Marjamäki 2016-01-26 16:53:01 +01:00
parent 5c9be4a0df
commit 462b98afbc
2 changed files with 7 additions and 0 deletions

View File

@ -584,6 +584,12 @@ static void valueFlowNumber(TokenList *tokenlist)
ValueFlow::Value value(tok->str() == "true");
value.setKnown();
setTokenValue(tok, value);
} else if (Token::Match(tok, "[(,] NULL [,)]")) {
// NULL function parameters are not simplified in the
// normal tokenlist
ValueFlow::Value value(0);
value.setKnown();
setTokenValue(tok->next(), value);
}
}
}

View File

@ -167,6 +167,7 @@ private:
ASSERT_EQUALS(123, valueOfTok("x=123;", "123").intvalue);
ASSERT_EQUALS(0, valueOfTok("x=false;", "false").intvalue);
ASSERT_EQUALS(1, valueOfTok("x=true;", "true").intvalue);
ASSERT_EQUALS(0, valueOfTok("x(NULL);", "NULL").intvalue);
ASSERT_EQUALS((int)('a'), valueOfTok("x='a';", "'a'").intvalue);
ASSERT_EQUALS((int)('\n'), valueOfTok("x='\\n';", "'\\n'").intvalue);
}