[PATCH] D153236: [NFC] Fix potential dereferencing of nullptr.

Mariya Podchishchaeva via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 19 04:04:36 PDT 2023


Fznamznon added inline comments.


================
Comment at: clang/lib/Parse/ParseStmt.cpp:887
+      else {
+        assert(DeepestParsedCaseStmt && "DeepestParsedCaseStmt cannot be null");
         Actions.ActOnCaseStmtBody(DeepestParsedCaseStmt, Case.get());
----------------
The assert that looks like `assert(x && "x should not be null")` seems strange. Failed `assert(x)` implies that `x` should not be null. If there is a message, a message saying what is wrong and why is much more useful.


================
Comment at: clang/lib/Sema/SemaExprObjC.cpp:2441
 
+  assert(receiverTypeInfo && "receiverTypeInfo cannot be null");
   return BuildClassMessage(receiverTypeInfo, ReceiverType,
----------------
That seems to be a strange place before and after changes. With or without change, when `ReceiverType.isNull()` is true we just end up passing `nullptr`  as `receiverTypeInfo ` to the `BuildClassMessage` which doesn't seem to be checking its non-nullness before dereferencing it, even though its description says that `receiverTypeInfo` can be null. 
I guess it is fine to pass `nullptr` to a function whose description says so, but the non-nullness check inside of it should be probably a bit more obvious than it is right now.


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

https://reviews.llvm.org/D153236



More information about the cfe-commits mailing list