[PATCH] D152977: [NFC] Fix potential dereferencing of null return value.

Sindhu Chittireddy via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 15 11:25:37 PDT 2023


schittir added inline comments.


================
Comment at: clang/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp:294-295
   // UntouchedAndPossiblyDestroyed or UnlockedAndPossiblyDestroyed.
-  assert(lstate->isUntouchedAndPossiblyDestroyed() ||
-         lstate->isUnlockedAndPossiblyDestroyed());
+  assert(lstate && (lstate->isUntouchedAndPossiblyDestroyed() ||
+                    lstate->isUnlockedAndPossiblyDestroyed()));
 
----------------
steakhal wrote:
> schittir wrote:
> > steakhal wrote:
> > > 
> > Wouldn't it be better to do an with a comment, like below?  
> > ```
> > assert(lstate && "lstate should not be null");
> > ```
> As a Static Analyzer dev I don't think its necessary. StateRefs are ubiquitous and here we probably know it cannot be null. And if it turns out to be null we would get a segfault. So that sense I don't think its necessary.
> 
> 
> And speaking of a comment like "it should not be null" I think the segfault would sort of imply that.
That makes sense! Thanks!


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

https://reviews.llvm.org/D152977



More information about the cfe-commits mailing list