* Add test for #6541, avoid duplicate warning * Add test for #5475 * Fix test
This commit is contained in:
parent
bc409776e3
commit
71f9a7269f
|
@ -288,7 +288,8 @@ void CheckNullPointer::nullPointerByDeRefAndChec()
|
||||||
if (Token::Match(tok, "%num%|%char%|%str%"))
|
if (Token::Match(tok, "%num%|%char%|%str%"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!isNullablePointer(tok, mSettings))
|
if (!isNullablePointer(tok, mSettings) ||
|
||||||
|
(tok->str() == "." && isNullablePointer(tok->astOperand2(), mSettings) && tok->astOperand2()->getValue(0))) // avoid duplicate warning
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Can pointer be NULL?
|
// Can pointer be NULL?
|
||||||
|
|
|
@ -667,6 +667,16 @@ private:
|
||||||
" *new int;\n"
|
" *new int;\n"
|
||||||
"}\n", /*inconclusive*/ true);
|
"}\n", /*inconclusive*/ true);
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Found suspicious operator '*', result is not used.\n", errout.str());
|
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() {
|
void vardecl() {
|
||||||
|
|
|
@ -993,6 +993,11 @@ private:
|
||||||
" if (p);\n"
|
" if (p);\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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() {
|
void nullpointer5() {
|
||||||
|
|
Loading…
Reference in New Issue