Support new/delete in new uninitialized variable checking; realloc() requires an initialized first argument.
This commit is contained in:
parent
c3e47f7eaa
commit
60b2b655df
|
@ -4103,6 +4103,9 @@
|
||||||
<!-- void *realloc(void *block, size_t newsize); -->
|
<!-- void *realloc(void *block, size_t newsize); -->
|
||||||
<function name="realloc">
|
<function name="realloc">
|
||||||
<noreturn>false</noreturn>
|
<noreturn>false</noreturn>
|
||||||
|
<arg nr="1">
|
||||||
|
<not-uninit/>
|
||||||
|
</arg>
|
||||||
<arg nr="2">
|
<arg nr="2">
|
||||||
<not-uninit/>
|
<not-uninit/>
|
||||||
</arg>
|
</arg>
|
||||||
|
|
|
@ -1495,6 +1495,11 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
|
||||||
*alloc = true;
|
*alloc = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (var.isPointer() && (_tokenizer->isC() || var.typeStartToken()->isStandardType() || (var.type() && var.type()->needInitialization == Type::True)) && Token::Match(tok->next(), "= new")) {
|
||||||
|
if (alloc)
|
||||||
|
*alloc = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!membervar.empty()) {
|
if (!membervar.empty()) {
|
||||||
|
@ -1676,7 +1681,7 @@ void CheckUninitVar::checkRhs(const Token *tok, const Variable &var, bool alloc,
|
||||||
|
|
||||||
bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool alloc) const
|
bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool alloc) const
|
||||||
{
|
{
|
||||||
if (!alloc && vartok->previous()->str() == "return" && vartok->strAt(1) != "=")
|
if (!alloc && ((Token::Match(vartok->previous(), "return|delete") && vartok->strAt(1) != "=") || (vartok->strAt(-1) == "]" && vartok->linkAt(-1)->strAt(-1) == "delete")))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Passing variable to typeof/__alignof__
|
// Passing variable to typeof/__alignof__
|
||||||
|
|
Loading…
Reference in New Issue