Fixed #4903 (Improve check: allocated but not initialized (condition))
This commit is contained in:
parent
95d8534d89
commit
255b788d4d
|
@ -522,8 +522,8 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
|
||||||
else if (Token::Match(tok, "for|while (") || Token::simpleMatch(tok, "do {")) {
|
else if (Token::Match(tok, "for|while (") || Token::simpleMatch(tok, "do {")) {
|
||||||
const bool forwhile = Token::Match(tok, "for|while (");
|
const bool forwhile = Token::Match(tok, "for|while (");
|
||||||
|
|
||||||
// is variable initialized in for-head (don't report errors yet)?
|
// is variable initialized in for-head?
|
||||||
if (forwhile && checkIfForWhileHead(tok->next(), var, true, false, *alloc, membervar))
|
if (forwhile && checkIfForWhileHead(tok->next(), var, tok->str() == "for", false, *alloc, membervar))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// goto the {
|
// goto the {
|
||||||
|
|
|
@ -3595,6 +3595,13 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkUninitVar("int f() {\n"
|
||||||
|
" char *p = (char *)malloc(256);\n"
|
||||||
|
" while(*p && *p == '_')\n"
|
||||||
|
" p++;\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("[test.cpp:3]: (error) Memory is allocated but not initialized: p\n", errout.str());
|
||||||
|
|
||||||
// #6646 - init in for loop
|
// #6646 - init in for loop
|
||||||
checkUninitVar("void f() {\n" // No FP
|
checkUninitVar("void f() {\n" // No FP
|
||||||
" for (int i;;i++)\n"
|
" for (int i;;i++)\n"
|
||||||
|
|
Loading…
Reference in New Issue