Uninitialized variables: Detect more errors when variable is given as array index. Ticket: #3369
This commit is contained in:
parent
63e2f64b9c
commit
295f486cde
|
@ -1157,6 +1157,9 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (vartok->strAt(-1) == "[" || vartok->strAt(1) == "]")
|
||||||
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1707,6 +1707,12 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: x\n", errout.str());
|
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"
|
checkUninitVar2("void f() {\n"
|
||||||
" int x;\n"
|
" int x;\n"
|
||||||
" int y = x & 3;\n"
|
" int y = x & 3;\n"
|
||||||
|
|
Loading…
Reference in New Issue