Uninitialized variables: Detect more errors when variable is given as array index. Ticket: #3369

This commit is contained in:
Daniel Marjamäki 2011-12-14 19:56:58 +01:00
parent 63e2f64b9c
commit 295f486cde
2 changed files with 9 additions and 0 deletions

View File

@ -1157,6 +1157,9 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok) const
}
}
if (vartok->strAt(-1) == "[" || vartok->strAt(1) == "]")
return true;
return false;
}

View File

@ -1707,6 +1707,12 @@ private:
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout.str());
checkUninitVar2("void f() {\n"
" int x;\n"
" str[x] = 0;\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout.str());
checkUninitVar2("void f() {\n"
" int x;\n"
" int y = x & 3;\n"