Fixed #1778 (false negative: nullpointer dereference (std::string pointer))
This commit is contained in:
parent
068317bed1
commit
a3367874d9
|
@ -2685,14 +2685,16 @@ private:
|
||||||
vartok = vartok->tokAt(3);
|
vartok = vartok->tokAt(3);
|
||||||
while (vartok && (vartok->str() == "*" || vartok->isName()))
|
while (vartok && (vartok->str() == "*" || vartok->isName()))
|
||||||
vartok = vartok->next();
|
vartok = vartok->next();
|
||||||
if (Token::Match(vartok, "> * %var% ;|="))
|
}
|
||||||
{
|
if (vartok
|
||||||
vartok = vartok->tokAt(2);
|
&& (vartok->str() == ">" || vartok->isName())
|
||||||
checks.push_back(new CheckNullpointer(owner, vartok->varId(), vartok->str()));
|
&& Token::Match(vartok->next(), "* %var% ;|="))
|
||||||
if (Token::simpleMatch(vartok->next(), "= 0 ;"))
|
{
|
||||||
setnull(checks, vartok->varId());
|
vartok = vartok->tokAt(2);
|
||||||
return vartok->next();
|
checks.push_back(new CheckNullpointer(owner, vartok->varId(), vartok->str()));
|
||||||
}
|
if (Token::simpleMatch(vartok->next(), "= 0 ;"))
|
||||||
|
setnull(checks, vartok->varId());
|
||||||
|
return vartok->next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1134,7 +1134,7 @@ private:
|
||||||
" std::string * x = 0;\n"
|
" std::string * x = 0;\n"
|
||||||
" *x = \"test\";\n"
|
" *x = \"test\";\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: x\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: x\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkUninitVar(const char code[])
|
void checkUninitVar(const char code[])
|
||||||
|
|
Loading…
Reference in New Issue