| 1509 | } |
| 1510 | |
| 1511 | bool CheckUninitVarImpl::isMemberVariableUsage(const Token *tok, bool isPointer, Alloc alloc, const std::string &membervar) const |
| 1512 | { |
| 1513 | if (Token::Match(tok->previous(), "[(,] %name% . %name% [,)]") && |
| 1514 | tok->strAt(2) == membervar) { |
| 1515 | const int use = isFunctionParUsage(tok, isPointer, alloc); |
| 1516 | if (use == 1) |
| 1517 | return true; |
| 1518 | } |
| 1519 | |
| 1520 | if (isMemberVariableAssignment(tok, membervar)) |
| 1521 | return false; |
| 1522 | |
| 1523 | if (Token::Match(tok, "%name% . %name%") && tok->strAt(2) == membervar && !(tok->tokAt(-2)->variable() && tok->tokAt(-2)->variable()->isReference())) { |
| 1524 | const Token *parent = tok->next()->astParent(); |
| 1525 | return !parent || !parent->isUnaryOp("&"); |
| 1526 | } |
| 1527 | if (!isPointer && !Token::simpleMatch(tok->astParent(), ".") && Token::Match(tok->previous(), "[(,] %name% [,)]") && isVariableUsage(tok, isPointer, alloc)) |
| 1528 | return true; |
| 1529 | |
| 1530 | if (!isPointer && Token::Match(tok->previous(), "= %name% ;")) { |
| 1531 | const Token* lhs = tok->previous()->astOperand1(); |
| 1532 | return !(lhs && lhs->variable() && lhs->variable()->isReference() && lhs == lhs->variable()->nameToken()); |
| 1533 | } |
| 1534 | |
| 1535 | // = *(&var); |
| 1536 | if (!isPointer && |
| 1537 | Token::simpleMatch(tok->astParent(),"&") && |
| 1538 | Token::simpleMatch(tok->astParent()->astParent(),"*") && |
| 1539 | Token::Match(tok->astParent()->astParent()->astParent(), "= * (| &") && |
| 1540 | tok->astParent()->astParent()->astParent()->astOperand2() == tok->astParent()->astParent()) |
| 1541 | return true; |
| 1542 | |
| 1543 | // TODO: this used to be experimental - enable or remove see #5586 |
| 1544 | if ((false) && // NOLINT(readability-simplify-boolean-expr,readability-redundant-parentheses) |
| 1545 | !isPointer && |
| 1546 | Token::Match(tok->tokAt(-2), "[(,] & %name% [,)]") && |
| 1547 | isVariableUsage(tok, isPointer, alloc)) |
| 1548 | return true; |
| 1549 | |
| 1550 | return false; |
| 1551 | } |
| 1552 | |
| 1553 | void CheckUninitVarImpl::uninitdataError(const Token *tok, const std::string &varname) |
| 1554 | { |
nothing calls this directly
no test coverage detected