[PATCH] D139148: Fix nullptr dereference found by Coverity static analysis tool

Tom Honermann via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 9 12:30:59 PST 2022


tahonermann added inline comments.


================
Comment at: clang/lib/Sema/SemaInit.cpp:5959
   if (DestType->isRecordType()) {
+    assert(Initializer && "Intializer must be non-null");
     //     - If the initialization is direct-initialization, or if it is
----------------
It looks like this assertion was triggered for both the Linux and Windows builds.

Since the `else` branch below unconditionally dereferences `Initializer`, I think the only way for `Initializer` to be null and for a crash not to occur is if the `then` branch is taken, but without `Initializer->getBeginLoc()` being evaluated due to short circuiting. I think we should do this:
1) Add a `Initializer &&` condition prior to the call to `S.IsDerivedFrom(Initializer->getBeginLoc(), ...)`. This will require yet more parenthesis for the conditional logic.
2) Add the assert to the `else` branch.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139148/new/

https://reviews.llvm.org/D139148



More information about the cfe-commits mailing list