Fix issue 9441: false positive: new(std::nothrow) and nullPointerRedundantCheck (#2403)
* Fix issue 9441: false positive: new(std::nothrow) and nullPointerRedundantCheck * Skip new if it is a variable
This commit is contained in:
parent
95bbc7a1e2
commit
a71f58ffc2
|
@ -322,6 +322,8 @@ static bool isNullablePointer(const Token* tok, const Settings* settings)
|
||||||
{
|
{
|
||||||
if (!tok)
|
if (!tok)
|
||||||
return false;
|
return false;
|
||||||
|
if (Token::simpleMatch(tok, "new") && tok->varId() == 0)
|
||||||
|
return false;
|
||||||
if (astIsPointer(tok))
|
if (astIsPointer(tok))
|
||||||
return true;
|
return true;
|
||||||
if (astIsSmartPointer(tok))
|
if (astIsSmartPointer(tok))
|
||||||
|
|
|
@ -85,7 +85,8 @@ private:
|
||||||
TEST_CASE(nullpointer43); // #9404
|
TEST_CASE(nullpointer43); // #9404
|
||||||
TEST_CASE(nullpointer44); // #9395, #9423
|
TEST_CASE(nullpointer44); // #9395, #9423
|
||||||
TEST_CASE(nullpointer45);
|
TEST_CASE(nullpointer45);
|
||||||
TEST_CASE(nullpointer46); // #6850
|
TEST_CASE(nullpointer46); // #9441
|
||||||
|
TEST_CASE(nullpointer47); // #6850
|
||||||
TEST_CASE(nullpointer_addressOf); // address of
|
TEST_CASE(nullpointer_addressOf); // address of
|
||||||
TEST_CASE(nullpointerSwitch); // #2626
|
TEST_CASE(nullpointerSwitch); // #2626
|
||||||
TEST_CASE(nullpointer_cast); // #4692
|
TEST_CASE(nullpointer_cast); // #4692
|
||||||
|
@ -1615,6 +1616,14 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void nullpointer46() {
|
void nullpointer46() {
|
||||||
|
check("void f() {\n"
|
||||||
|
" char* p = new(std::nothrow) char[1];\n"
|
||||||
|
" if( p ) {}\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void nullpointer47() {
|
||||||
check("void f(int *p) {\n"
|
check("void f(int *p) {\n"
|
||||||
" if(!p[0]) {}\n"
|
" if(!p[0]) {}\n"
|
||||||
" const int *const a = p;\n"
|
" const int *const a = p;\n"
|
||||||
|
|
Loading…
Reference in New Issue