DeclCXX - Fix getAs<> null-dereference static analyzer warnings. NFCI.

getAs<> can return null if the cast is invalid, which can lead to null pointer deferences. Use castAs<> instead which will assert that the cast is valid.
This commit is contained in:
Simon Pilgrim 2021-01-04 15:12:55 +00:00
parent 82a29a62ab
commit 9f8c0d15c7
1 changed files with 3 additions and 3 deletions

View File

@ -1508,7 +1508,7 @@ CXXMethodDecl *CXXRecordDecl::getLambdaCallOperator() const {
CXXMethodDecl* CXXRecordDecl::getLambdaStaticInvoker() const {
CXXMethodDecl *CallOp = getLambdaCallOperator();
CallingConv CC = CallOp->getType()->getAs<FunctionType>()->getCallConv();
CallingConv CC = CallOp->getType()->castAs<FunctionType>()->getCallConv();
return getLambdaStaticInvoker(CC);
}
@ -1532,8 +1532,8 @@ CXXMethodDecl *CXXRecordDecl::getLambdaStaticInvoker(CallingConv CC) const {
DeclContext::lookup_result Invoker = getLambdaStaticInvokers(*this);
for (NamedDecl *ND : Invoker) {
const FunctionType *FTy =
cast<ValueDecl>(ND->getAsFunction())->getType()->getAs<FunctionType>();
const auto *FTy =
cast<ValueDecl>(ND->getAsFunction())->getType()->castAs<FunctionType>();
if (FTy->getCallConv() == CC)
return getInvokerAsMethod(ND);
}