Uninitialized variables; Fixed FP in range based for loop
This commit is contained in:
parent
4322311482
commit
bde8b4316e
|
@ -1132,6 +1132,13 @@ const Token* CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer,
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LHS in range for loop:
|
||||||
|
if (Token::simpleMatch(valueExpr->astParent(), ":") &&
|
||||||
|
astIsLhs(valueExpr) &&
|
||||||
|
valueExpr->astParent()->astParent() &&
|
||||||
|
Token::simpleMatch(valueExpr->astParent()->astParent()->previous(), "for ("))
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
// Stream read/write
|
// Stream read/write
|
||||||
// FIXME this code is a hack!!
|
// FIXME this code is a hack!!
|
||||||
if (mTokenizer->isCPP() && Token::Match(valueExpr->astParent(), "<<|>>")) {
|
if (mTokenizer->isCPP() && Token::Match(valueExpr->astParent(), "<<|>>")) {
|
||||||
|
|
|
@ -4121,14 +4121,20 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void uninitvar_rangeBasedFor() { // #7078
|
void uninitvar_rangeBasedFor() {
|
||||||
checkUninitVar("void function(Entry& entry) {\n"
|
checkUninitVar("void function(Entry& entry) {\n" // #7078
|
||||||
" for (auto* expr : entry.exprs) {\n"
|
" for (auto* expr : entry.exprs) {\n"
|
||||||
" expr->operate();\n"
|
" expr->operate();\n"
|
||||||
" expr->operate();\n"
|
" expr->operate();\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkUninitVar("void f() {\n"
|
||||||
|
" int *item;\n"
|
||||||
|
" for (item: itemList) {}\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void uninitvar_static() { // #8734
|
void uninitvar_static() { // #8734
|
||||||
|
|
Loading…
Reference in New Issue