Uninitialized variables; Fixed false positive for 'cin >> x[0]'

This commit is contained in:
Daniel Marjamäki 2021-05-18 20:13:27 +02:00
parent 4b11bb4ad3
commit 0aebc32ae0
2 changed files with 9 additions and 0 deletions

View File

@ -1163,6 +1163,9 @@ const Token* CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer,
return nullptr;
}
}
if (astIsRhs(derefValue) && isLikelyStreamRead(mTokenizer->isCPP(), derefValue->astParent()))
return nullptr;
if (mTokenizer->isCPP() && Token::simpleMatch(valueExpr->astParent(), "&") && !valueExpr->astParent()->astParent() && astIsRhs(valueExpr) && Token::Match(valueExpr->astSibling(), "%type%"))
return nullptr;

View File

@ -421,6 +421,12 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVar("void f() {\n"
" int ret[2];\n"
" std::cin >> ret[0];\n"
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVar("void f(int i) {\n"
" int a;\n"
" i >> a;\n"