Uninitialized variables; Improved handling of function parameter

This commit is contained in:
Daniel Marjamäki 2021-05-23 14:36:56 +02:00
parent d64aea90fa
commit cbbd7f0bd0
1 changed files with 8 additions and 4 deletions

View File

@ -1149,8 +1149,6 @@ const Token* CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer,
return nullptr; return nullptr;
// FIXME handle address of!! // FIXME handle address of!!
if (valueExpr->astParent()->isUnaryOp("&"))
return nullptr;
if (derefValue && derefValue->astParent() && derefValue->astParent()->isUnaryOp("&")) if (derefValue && derefValue->astParent() && derefValue->astParent()->isUnaryOp("&"))
return nullptr; return nullptr;
@ -1193,6 +1191,14 @@ const Token* CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer,
const int use = isFunctionParUsage(derefValue, false, NO_ALLOC, indirect); const int use = isFunctionParUsage(derefValue, false, NO_ALLOC, indirect);
return (use>0) ? derefValue : nullptr; return (use>0) ? derefValue : nullptr;
} }
if (valueExpr->astParent()->isUnaryOp("&")) {
const Token *parent = valueExpr->astParent();
if (Token::Match(parent->astParent(), "[(,]") && (parent->astParent()->str() == "," || astIsRhs(parent))) {
const int use = isFunctionParUsage(valueExpr, pointer, alloc, indirect);
return (use>0) ? valueExpr : nullptr;
}
return nullptr;
}
// Assignments; // Assignments;
// * Is this LHS in assignment // * Is this LHS in assignment
@ -1323,8 +1329,6 @@ int CheckUninitVar::isFunctionParUsage(const Token *vartok, bool pointer, Alloc
return -1; return -1;
return 1; return 1;
} }
if ((pointer || address) && alloc == NO_ALLOC && Token::Match(argStart, "const struct| %type% * %name% [,)]"))
return 1;
if ((pointer || address) && Token::Match(argStart, "const %type% %name% [") && Token::Match(argStart->linkAt(3), "] [,)]")) if ((pointer || address) && Token::Match(argStart, "const %type% %name% [") && Token::Match(argStart->linkAt(3), "] [,)]"))
return 1; return 1;
} }