Null pointer: Fixed FP when there are 'return p?p->x:0;'
This commit is contained in:
parent
f16c30248a
commit
f127d56719
|
@ -1013,6 +1013,8 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
|
|||
nullPointerError(tok2, pointerName, vartok, inconclusive);
|
||||
else if (unknown)
|
||||
nullPointerError(tok2, pointerName, vartok, true);
|
||||
if (Token::Match(tok2, "%var% ?"))
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -1679,6 +1679,18 @@ private:
|
|||
" *x = 0;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// return ?:
|
||||
check("int f(ABC *p) {\n" // FP : return ?:
|
||||
" if (!p) {}\n"
|
||||
" return p ? p->x : 0;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
check("int f(ABC *p) {\n" // no fn
|
||||
" if (!p) {}\n"
|
||||
" return q ? p->x : 0;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (error) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
|
||||
}
|
||||
|
||||
// Test CheckNullPointer::nullConstantDereference
|
||||
|
|
Loading…
Reference in New Issue