Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/checknullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ void CheckNullPointer::nullPointerByDeRefAndChec()
if (Token::Match(tok, "%num%|%char%|%str%"))
continue;

if (!isNullablePointer(tok, mSettings))
if (!isNullablePointer(tok, mSettings) ||
(tok->str() == "." && isNullablePointer(tok->astOperand2(), mSettings) && tok->astOperand2()->getValue(0))) // avoid duplicate warning
continue;

// Can pointer be NULL?
Expand Down
10 changes: 10 additions & 0 deletions test/testincompletestatement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,16 @@ class TestIncompleteStatement : public TestFixture {
" *new int;\n"
"}\n", /*inconclusive*/ true);
ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Found suspicious operator '*', result is not used.\n", errout.str());

check("void f() {\n" // #5475
" std::string(\"a\") + \"a\";\n"
"}\n"
"void f(std::string& a) {\n"
" a.erase(3) + \"suf\";\n"
"}\n", /*inconclusive*/ true);
ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Found suspicious operator '+', result is not used.\n"
"[test.cpp:5]: (warning, inconclusive) Found suspicious operator '+', result is not used.\n",
errout.str());
}

void vardecl() {
Expand Down
5 changes: 5 additions & 0 deletions test/testnullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,11 @@ class TestNullPointer : public TestFixture {
" if (p);\n"
"}");
ASSERT_EQUALS("", errout.str());

check("struct S { struct T { char c; } *p; };\n" // #6541
"char f(S* s) { return s->p ? 'a' : s->p->c; }\n");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (warning) Either the condition 's->p' is redundant or there is possible null pointer dereference: p.\n",
errout.str());
}

void nullpointer5() {
Expand Down