Skip to content

Commit b571e9f

Browse files
authored
Fix issue 10106: FP: nullPointerRedundantCheck (#3044)
1 parent b469da1 commit b571e9f

3 files changed

Lines changed: 7 additions & 2 deletions

File tree

lib/programmemory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ void execute(const Token *expr,
377377
if (!expr)
378378
*error = true;
379379

380-
else if (expr->hasKnownIntValue()) {
380+
else if (expr->hasKnownIntValue() && !expr->isAssignmentOp()) {
381381
*result = expr->values().front().intvalue;
382382
}
383383

lib/valueflow.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,11 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
431431
if (!parent)
432432
return;
433433

434+
if (Token::simpleMatch(parent, "=") && astIsRHS(tok) && !value.isLifetimeValue()) {
435+
setTokenValue(parent, value, settings);
436+
return;
437+
}
438+
434439
if (value.isContainerSizeValue()) {
435440
// .empty, .size, +"abc", +'a'
436441
if (Token::Match(parent, "+|==|!=") && parent->astOperand1() && parent->astOperand2()) {

test/testvalueflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4051,7 +4051,7 @@ class TestValueFlow : public TestFixture {
40514051
" return((n=42) && *n == 'A');\n"
40524052
"}";
40534053
values = tokenValues(code, "n ==");
4054-
ASSERT_EQUALS(true, values.size() != 1U || !values.front().isUninitValue());
4054+
ASSERT_EQUALS(true, values.empty());
40554055

40564056
// #8233
40574057
code = "void foo() {\n"

0 commit comments

Comments
 (0)