Uninitialized variables; use AST
This commit is contained in:
parent
e73057eb44
commit
2c155a7a78
|
@ -1109,14 +1109,14 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, Alloc al
|
|||
}
|
||||
|
||||
// is there something like: ; "*((&var ..expr.. =" => the variable is assigned
|
||||
if (vartok->previous()->str() == "&" && !vartok->previous()->astOperand2())
|
||||
if (vartok->astParent()->isUnaryOp("&"))
|
||||
return false;
|
||||
|
||||
// bailout to avoid fp for 'int x = 2 + x();' where 'x()' is a unseen preprocessor macro (seen in linux)
|
||||
if (!pointer && vartok->next() && vartok->next()->str() == "(")
|
||||
return false;
|
||||
|
||||
if (alloc != NO_ALLOC && vartok->previous()->str() == "*") {
|
||||
if (alloc != NO_ALLOC && vartok->astParent()->isUnaryOp("*")) {
|
||||
// TestUninitVar::isVariableUsageDeref()
|
||||
const Token *parent = vartok->previous()->astParent();
|
||||
if (parent && parent->str() == "=" && parent->astOperand1() == vartok->previous())
|
||||
|
@ -1126,7 +1126,7 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, Alloc al
|
|||
return true;
|
||||
}
|
||||
|
||||
if (vartok->previous()->str() != "&" || !Token::Match(vartok->tokAt(-2), "[(,=?:]"))
|
||||
if (!vartok->astParent()->isUnaryOp("&") || !Token::Match(vartok->tokAt(-2), "[(,=?:]"))
|
||||
return alloc == NO_ALLOC;
|
||||
}
|
||||
|
||||
|
|
|
@ -1756,9 +1756,9 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void array_index_bounds() {
|
||||
// #10275
|
||||
check("int a[10];\n"
|
||||
void array_index_bounds() {
|
||||
// #10275
|
||||
check("int a[10];\n"
|
||||
"void f(int i) {\n"
|
||||
" if (i >= 0 && i < 10) {}\n"
|
||||
" a[i] = 1;\n"
|
||||
|
@ -1766,7 +1766,7 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition 'i<10' is redundant or the array 'a[10]' is accessed at index 10, which is out of bounds.\n"
|
||||
"[test.cpp:3] -> [test.cpp:4]: (warning) Either the condition 'i>=0' is redundant or the array 'a[10]' is accessed at index -1, which is out of bounds.\n",
|
||||
errout.str());
|
||||
}
|
||||
}
|
||||
|
||||
void array_index_calculation() {
|
||||
// #1193 - false negative: array out of bounds in loop when there is calculation
|
||||
|
|
Loading…
Reference in New Issue