This is an archive of the discontinued LLVM Phabricator instance.

[NFC][CLANG] Fix issue with dereference null return value found by Coverity
ClosedPublic

Authored by Manna on May 23 2023, 8:38 PM.

Details

Summary

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.

Diff Detail

Event Timeline

Manna created this revision.May 23 2023, 8:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 23 2023, 8:38 PM
Manna requested review of this revision.May 23 2023, 8:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 23 2023, 8:38 PM
Manna edited the summary of this revision. (Show Details)May 23 2023, 8:41 PM
erichkeane accepted this revision.May 24 2023, 6:00 AM
This revision is now accepted and ready to land.May 24 2023, 6:00 AM
Manna added a comment.May 24 2023, 5:30 PM

Thank you @erichkeane for reviews!