[clang] 7562f3d - InvalidPtrChecker - don't dereference a dyn_cast<> - use cast<> instead.

Simon Pilgrim via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 20 10:07:25 PDT 2021


Author: Simon Pilgrim
Date: 2021-10-20T18:06:00+01:00
New Revision: 7562f3df89066ab92a816dc23005c45fd642bdf9

URL: https://github.com/llvm/llvm-project/commit/7562f3df89066ab92a816dc23005c45fd642bdf9
DIFF: https://github.com/llvm/llvm-project/commit/7562f3df89066ab92a816dc23005c45fd642bdf9.diff

LOG: InvalidPtrChecker - don't dereference a dyn_cast<> - use cast<> instead.

Avoid dereferencing a nullptr returned by dyn_cast<>, by using cast<> instead which asserts that the cast is valid.

Added: 
    

Modified: 
    clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
index 18893c2fda15b..378d7ce8150af 100644
--- a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
@@ -146,7 +146,7 @@ void InvalidPtrChecker::postPreviousReturnInvalidatingCall(
   State = State->BindExpr(CE, LCtx, RetVal);
 
   // Remember to this region.
-  const auto *SymRegOfRetVal = dyn_cast<SymbolicRegion>(RetVal.getAsRegion());
+  const auto *SymRegOfRetVal = cast<SymbolicRegion>(RetVal.getAsRegion());
   const MemRegion *MR =
       const_cast<MemRegion *>(SymRegOfRetVal->getBaseRegion());
   State = State->set<PreviousCallResultMap>(FD, MR);


        


More information about the cfe-commits mailing list