| 3561 | } |
| 3562 | |
| 3563 | static void valueFlowSymbolic(const TokenList& tokenlist, const SymbolDatabase& symboldatabase, ErrorLogger& errorLogger, const Settings& settings) |
| 3564 | { |
| 3565 | for (const Scope* scope : symboldatabase.functionScopes) { |
| 3566 | for (auto* tok = const_cast<Token*>(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) { |
| 3567 | if (!Token::simpleMatch(tok, "=")) |
| 3568 | continue; |
| 3569 | if (tok->astParent()) |
| 3570 | continue; |
| 3571 | if (!tok->astOperand1()) |
| 3572 | continue; |
| 3573 | if (!tok->astOperand2()) |
| 3574 | continue; |
| 3575 | if (tok->astOperand1()->hasKnownIntValue()) |
| 3576 | continue; |
| 3577 | if (tok->astOperand2()->hasKnownIntValue()) |
| 3578 | continue; |
| 3579 | if (tok->astOperand1()->exprId() == 0) |
| 3580 | continue; |
| 3581 | if (tok->astOperand2()->exprId() == 0) |
| 3582 | continue; |
| 3583 | if (!isConstExpression(tok->astOperand2(), settings.library)) |
| 3584 | continue; |
| 3585 | if (tok->astOperand1()->valueType() && tok->astOperand2()->valueType()) { |
| 3586 | if (isTruncated( |
| 3587 | tok->astOperand2()->valueType(), tok->astOperand1()->valueType(), settings)) |
| 3588 | continue; |
| 3589 | } else if (isDifferentType(tok->astOperand2(), tok->astOperand1(), settings)) { |
| 3590 | continue; |
| 3591 | } |
| 3592 | const std::set<nonneg int> rhsVarIds = getVarIds(tok->astOperand2()); |
| 3593 | const std::vector<const Variable*> vars = getLHSVariables(tok); |
| 3594 | if (std::any_of(vars.cbegin(), vars.cend(), [&](const Variable* var) { |
| 3595 | if (rhsVarIds.count(var->declarationId()) > 0) |
| 3596 | return true; |
| 3597 | if (var->isLocal()) |
| 3598 | return var->isStatic(); |
| 3599 | return !var->isArgument(); |
| 3600 | })) |
| 3601 | continue; |
| 3602 | |
| 3603 | if (findAstNode(tok, [](const Token* child) { |
| 3604 | return child->isIncompleteVar(); |
| 3605 | })) |
| 3606 | continue; |
| 3607 | |
| 3608 | Token* start = nextAfterAstRightmostLeaf(tok); |
| 3609 | const Token* end = ValueFlow::getEndOfExprScope(tok->astOperand1(), scope); |
| 3610 | |
| 3611 | ValueFlow::Value rhs = makeSymbolic(tok->astOperand2()); |
| 3612 | rhs.errorPath.emplace_back(tok, |
| 3613 | tok->astOperand1()->expressionString() + " is assigned '" + |
| 3614 | tok->astOperand2()->expressionString() + "' here."); |
| 3615 | valueFlowForward(start, end, tok->astOperand1(), std::move(rhs), tokenlist, errorLogger, settings); |
| 3616 | |
| 3617 | ValueFlow::Value lhs = makeSymbolic(tok->astOperand1()); |
| 3618 | lhs.errorPath.emplace_back(tok, |
| 3619 | tok->astOperand1()->expressionString() + " is assigned '" + |
| 3620 | tok->astOperand2()->expressionString() + "' here."); |
no test coverage detected