Skip to content

Commit ad571e0

Browse files
committed
[NFC][CLANG] Fix issue with dereference null return value found by Coverity
Reported by Static Analyzer Tool, Coverity: Inside "SemaDeclCXX.cpp" file, in clang::Sema::CheckExplicitlyDefaultedSpecialMember(clang::CXXMethodDecl *, clang::Sema::CXXSpecialMember, clang::SourceLocation): Return value of function which returns null is dereferenced without checking. //returned_null: getAs returns nullptr (checked 117 out of 143 times). // var_assigned: Assigning: Type = nullptr return value from getAs. const FunctionProtoType *Type = MD->getType()->getAs<FunctionProtoType>(); //Dereference null return value (NULL_RETURNS) //dereference: Dereferencing a pointer that might be nullptr Type when calling getReturnType. ReturnType = Type->getReturnType(); //Dereference null return value (NULL_RETURNS) //dereference: Dereferencing a pointer that might be nullptr Type when calling getParamType. QualType ArgType = ExpectedParams ? Type->getParamType(0) : QualType(); This patch uses castAs instead of getAs which will assert if the type doesn't match. Reviewed By: erichkeane Differential Revision: https://reviews.llvm.org/D151281
1 parent d0d26ee commit ad571e0

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7517,7 +7517,7 @@ bool Sema::CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD,
75177517
}
75187518
}
75197519

7520-
const FunctionProtoType *Type = MD->getType()->getAs<FunctionProtoType>();
7520+
const FunctionProtoType *Type = MD->getType()->castAs<FunctionProtoType>();
75217521

75227522
bool CanHaveConstParam = false;
75237523
if (CSM == CXXCopyConstructor)

0 commit comments

Comments
 (0)