Uninitialized variables; Fixed FP in valueflow-based checking
This commit is contained in:
parent
f968761382
commit
8ad0905e3b
|
@ -1532,8 +1532,12 @@ void CheckUninitVar::valueFlowUninit()
|
||||||
const bool isarray = !tok->variable() || tok->variable()->isArray();
|
const bool isarray = !tok->variable() || tok->variable()->isArray();
|
||||||
const bool ispointer = astIsPointer(tok) && !isarray;
|
const bool ispointer = astIsPointer(tok) && !isarray;
|
||||||
const bool deref = CheckNullPointer::isPointerDeRef(tok, unknown, mSettings);
|
const bool deref = CheckNullPointer::isPointerDeRef(tok, unknown, mSettings);
|
||||||
if (ispointer && v->indirect == 1 && !deref)
|
if (ispointer && !deref) {
|
||||||
continue;
|
if (v->indirect >= 1)
|
||||||
|
continue;
|
||||||
|
if (!isVariableUsage(tok, true, NO_ALLOC, 0))
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (isarray && !deref)
|
if (isarray && !deref)
|
||||||
continue;
|
continue;
|
||||||
uninitderef = deref && v->indirect == 0;
|
uninitderef = deref && v->indirect == 0;
|
||||||
|
|
|
@ -4474,14 +4474,12 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
valueFlowUninit("int a(FArchive &arc) {\n"
|
valueFlowUninit("int a(FArchive &arc) {\n" // #3060 (initialization through operator<<)
|
||||||
" int *p;\n"
|
" int *p;\n"
|
||||||
" arc << p;\n"
|
" arc << p;\n"
|
||||||
" return *p;\n"
|
" return *p;\n" // fp: should not warn
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: p\n"
|
TODO_ASSERT_EQUALS("", "[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str());
|
||||||
"[test.cpp:4]: (error) Uninitialized variable: p\n",
|
|
||||||
errout.str());
|
|
||||||
|
|
||||||
// #4320
|
// #4320
|
||||||
valueFlowUninit("void f() {\n"
|
valueFlowUninit("void f() {\n"
|
||||||
|
@ -4603,6 +4601,12 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
valueFlowUninit("void foo(struct qb_list_head *list) {\n"
|
||||||
|
" struct qb_list_head *iter;\n"
|
||||||
|
" qb_list_for_each(iter, list) {}\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
valueFlowUninit("int foo()\n"
|
valueFlowUninit("int foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" int i;\n"
|
" int i;\n"
|
||||||
|
|
Loading…
Reference in New Issue