Fixed #2691 (False positive: struct dereference and check (switch-break))

This commit is contained in:
Daniel Marjamäki 2011-03-28 17:28:21 +02:00
parent ccf1282c91
commit 4a7b60942b
2 changed files with 15 additions and 2 deletions

View File

@ -460,8 +460,8 @@ void CheckNullPointer::nullPointerStructByDeRefAndChec()
else if (tok2->str() == "do")
break;
// return at base level => stop checking
else if (indentlevel2 == 0 && tok2->str() == "return")
// return/break at base level => stop checking
else if (indentlevel2 == 0 && (tok2->str() == "return" || tok2->str() == "break"))
break;
// Function call: If the pointer is not a local variable it

View File

@ -360,6 +360,19 @@ private:
" if (abc) { }\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (error) Possible null pointer dereference: abc - otherwise it is redundant to check if abc is null at line 4\n",errout.str());
// #2691 - switch/break
check("void f(ABC *abc) {\n"
" switch ( x ) {\n"
" case 14:\n"
" sprintf(buf, \"%d\", abc->a);\n"
" break;\n"
" case 15:\n"
" if ( abc ) {}\n"
" break;\n"
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
}
// Dereferencing a pointer and then checking if it is null