Fixed #1893 (false positive: dereferencing null pointer (try/catch))
This commit is contained in:
parent
dfbdd8f9c4
commit
9c17114668
|
@ -2713,6 +2713,26 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
if (Token::simpleMatch(&tok, "try {"))
|
||||
{
|
||||
// Bail out all used variables
|
||||
unsigned int indentlevel = 0;
|
||||
for (const Token *tok2 = &tok; tok2; tok2 = tok2->next())
|
||||
{
|
||||
if (tok2->str() == "{")
|
||||
++indentlevel;
|
||||
else if (tok2->str() == "}")
|
||||
{
|
||||
if (indentlevel == 0)
|
||||
break;
|
||||
if (indentlevel == 1 && !Token::simpleMatch(tok2,"} catch ("))
|
||||
return tok2;
|
||||
--indentlevel;
|
||||
}
|
||||
else if (tok2->varId())
|
||||
bailOutVar(checks,tok2->varId());
|
||||
}
|
||||
}
|
||||
|
||||
if (Token::Match(&tok, "%var% ("))
|
||||
{
|
||||
|
|
|
@ -1111,6 +1111,41 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// Ticket #1893 - try/catch inside else
|
||||
checkNullPointer("int *test(int *Z)\n"
|
||||
"{\n"
|
||||
" int *Q=NULL;\n"
|
||||
" if (Z) {\n"
|
||||
" Q = Z;\n"
|
||||
" }\n"
|
||||
" else {\n"
|
||||
" Z = new int;\n"
|
||||
" try {\n"
|
||||
" } catch(...) {\n"
|
||||
" }\n"
|
||||
" Q = Z;\n"
|
||||
" }\n"
|
||||
" *Q=1;\n"
|
||||
" return Q;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkNullPointer("int *test(int *Z)\n"
|
||||
"{\n"
|
||||
" int *Q=NULL;\n"
|
||||
" if (Z) {\n"
|
||||
" Q = Z;\n"
|
||||
" }\n"
|
||||
" else {\n"
|
||||
" try {\n"
|
||||
" } catch(...) {\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" *Q=1;\n"
|
||||
" return Q;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:12]: (error) Possible null pointer dereference: Q\n", errout.str());
|
||||
|
||||
// function pointer..
|
||||
checkNullPointer("void foo()\n"
|
||||
"{\n"
|
||||
|
|
Loading…
Reference in New Issue