Fix issue 10106: FP: nullPointerRedundantCheck (#3044)

This commit is contained in:
Paul Fultz II 2021-01-13 05:36:26 -06:00 committed by GitHub
parent b469da1069
commit b571e9fe0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 2 deletions

View File

@ -377,7 +377,7 @@ void execute(const Token *expr,
if (!expr)
*error = true;
else if (expr->hasKnownIntValue()) {
else if (expr->hasKnownIntValue() && !expr->isAssignmentOp()) {
*result = expr->values().front().intvalue;
}

View File

@ -431,6 +431,11 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
if (!parent)
return;
if (Token::simpleMatch(parent, "=") && astIsRHS(tok) && !value.isLifetimeValue()) {
setTokenValue(parent, value, settings);
return;
}
if (value.isContainerSizeValue()) {
// .empty, .size, +"abc", +'a'
if (Token::Match(parent, "+|==|!=") && parent->astOperand1() && parent->astOperand2()) {

View File

@ -4051,7 +4051,7 @@ private:
" return((n=42) && *n == 'A');\n"
"}";
values = tokenValues(code, "n ==");
ASSERT_EQUALS(true, values.size() != 1U || !values.front().isUninitValue());
ASSERT_EQUALS(true, values.empty());
// #8233
code = "void foo() {\n"