[PATCH] D151281: [NFC][CLANG] Fix issue with dereference null return value found by Coverity
Soumi Manna via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 23 20:38:15 PDT 2023
Manna created this revision.
Manna added a reviewer: erichkeane.
Herald added a project: All.
Manna requested review of this revision.
Herald added a project: clang.
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). [show details]
// 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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D151281
Files:
clang/lib/Sema/SemaDeclCXX.cpp
Index: clang/lib/Sema/SemaDeclCXX.cpp
===================================================================
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -7517,7 +7517,7 @@
}
}
- const FunctionProtoType *Type = MD->getType()->getAs<FunctionProtoType>();
+ const FunctionProtoType *Type = MD->getType()->castAs<FunctionProtoType>();
bool CanHaveConstParam = false;
if (CSM == CXXCopyConstructor)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151281.524984.patch
Type: text/x-patch
Size: 440 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230524/539524a8/attachment.bin>
More information about the cfe-commits
mailing list