Skip to content

Commit a93e76d

Browse files
authored
[clang][dataflow] Reorder checks to protect against a null pointer dereference. (#66764)
I've received a report of a null pointer dereference happening on the `LocDst->getType()` dereference. I wasn't unfortunately able to find a repro, but I'd argue the new version is better for the reduced indentation alone.
1 parent 678c1f1 commit a93e76d

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

clang/lib/Analysis/FlowSensitive/Transfer.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -531,17 +531,18 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> {
531531
auto *LocDst =
532532
cast_or_null<RecordStorageLocation>(Env.getStorageLocation(*Arg0));
533533

534+
if (LocSrc == nullptr || LocDst == nullptr)
535+
return;
536+
534537
// The assignment operators are different from the type of the destination
535-
// in this model (i.e. in one of their base classes). This must be very rare
536-
// and we just bail.
538+
// in this model (i.e. in one of their base classes). This must be very
539+
// rare and we just bail.
537540
if (Method->getThisObjectType().getCanonicalType().getUnqualifiedType() !=
538541
LocDst->getType().getCanonicalType().getUnqualifiedType())
539542
return;
540543

541-
if (LocSrc != nullptr && LocDst != nullptr) {
542-
copyRecord(*LocSrc, *LocDst, Env);
543-
Env.setStorageLocation(*S, *LocDst);
544-
}
544+
copyRecord(*LocSrc, *LocDst, Env);
545+
Env.setStorageLocation(*S, *LocDst);
545546
}
546547
}
547548

0 commit comments

Comments
 (0)