Uninitialized variables: Fixed false positives (caused by my 'check more variables' commit)
This commit is contained in:
parent
5aaec7adc5
commit
5bac8eca37
|
@ -1059,12 +1059,15 @@ void CheckUninitVar::check()
|
|||
stdtype = true;
|
||||
else if (tok->str() == "*")
|
||||
pointer = true;
|
||||
else if (tok->isName() && tok->next()->str() == ";") {
|
||||
if (stdtype || pointer || _tokenizer->isC())
|
||||
else if (Token::Match(tok, "struct %type%"))
|
||||
tok = tok->next();
|
||||
else {
|
||||
if (tok->isName() && tok->next()->str() == ";" &&
|
||||
(stdtype || pointer)) {
|
||||
checkScopeForVariable(tok->next(), tok->varId(), pointer, NULL);
|
||||
}
|
||||
break;
|
||||
} else if (!tok->isName())
|
||||
break;
|
||||
}
|
||||
tok = tok->next();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1739,6 +1739,12 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: abc\n", errout.str());
|
||||
|
||||
checkUninitVar2("int f() {\n"
|
||||
" static int x;\n"
|
||||
" return ++x;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// using uninit var in condition
|
||||
checkUninitVar2("void f() {\n"
|
||||
" int x;\n"
|
||||
|
|
Loading…
Reference in New Issue