[PATCH] D139148: Fix nullptr dereference found by Coverity static analysis tool
Sindhu Chittireddy via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 9 12:56:36 PST 2022
schittir updated this revision to Diff 481732.
schittir added a comment.
Add `(Initializer && ` and assert to else branch per Tom's comments.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D139148/new/
https://reviews.llvm.org/D139148
Files:
clang/lib/Sema/SemaInit.cpp
Index: clang/lib/Sema/SemaInit.cpp
===================================================================
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -5936,6 +5936,7 @@
// We're at the end of the line for C: it's either a write-back conversion
// or it's a C assignment. There's no need to check anything else.
if (!S.getLangOpts().CPlusPlus) {
+ assert(Initializer && "Intializer must be non-null");
// If allowed, check whether this is an Objective-C writeback conversion.
if (allowObjCWritebackConversion &&
tryObjCWritebackConversion(S, *this, Entity, Initializer)) {
@@ -5962,7 +5963,8 @@
if (Kind.getKind() == InitializationKind::IK_Direct ||
(Kind.getKind() == InitializationKind::IK_Copy &&
(Context.hasSameUnqualifiedType(SourceType, DestType) ||
- S.IsDerivedFrom(Initializer->getBeginLoc(), SourceType, DestType))))
+ (Initilializer &&
+ S.IsDerivedFrom(Initializer->getBeginLoc(), SourceType, DestType)))))
TryConstructorInitialization(S, Entity, Kind, Args,
DestType, DestType, *this);
// - Otherwise (i.e., for the remaining copy-initialization cases),
@@ -5971,9 +5973,11 @@
// used) to a derived class thereof are enumerated as described in
// 13.3.1.4, and the best one is chosen through overload resolution
// (13.3).
- else
+ else {
+ assert(Initializer && "Intializer must be non-null");
TryUserDefinedConversion(S, DestType, Kind, Initializer, *this,
TopLevelOfInitList);
+ }
return;
}
@@ -6022,6 +6026,7 @@
// - Otherwise, if the source type is a (possibly cv-qualified) class
// type, conversion functions are considered.
if (!SourceType.isNull() && SourceType->isRecordType()) {
+ assert(Initializer && "Intializer must be non-null");
// For a conversion to _Atomic(T) from either T or a class type derived
// from T, initialize the T object then convert to _Atomic type.
bool NeedAtomicConversion = false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139148.481732.patch
Type: text/x-patch
Size: 2117 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221209/1e3282d8/attachment-0001.bin>
More information about the cfe-commits
mailing list