[PATCH] D81061: [Analyzer][VLASizeChecker] Fix problem with zero index assumption.

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 8 05:58:07 PDT 2020


NoQ added inline comments.


================
Comment at: clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp:130-131
+        // At least check for zero again.
+        // Assume that this is a more exact fact than the previous assumptions
+        // (in checkVLAIndexSize), so report error too.
+        reportBug(VLA_Zero, SizeE, State, C);
----------------
Why not do the same in `checkVLAIndexSize` then?


================
Comment at: clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp:182-183
 
-  SVal LessThanZeroVal = SVB.evalBinOp(State, BO_LT, SizeD, Zero, SizeTy);
-  if (Optional<DefinedSVal> LessThanZeroDVal =
-          LessThanZeroVal.getAs<DefinedSVal>()) {
-    ConstraintManager &CM = C.getConstraintManager();
-    ProgramStateRef StatePos, StateNeg;
+  // Check if the size is zero or negative.
+  SVal PositiveVal = SVB.evalBinOp(State, BO_GT, SizeD, Zero, SizeTy);
+  if (Optional<DefinedSVal> PositiveDVal = PositiveVal.getAs<DefinedSVal>()) {
----------------
The type of binary operator `>=` is `bool`, not `size_t`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81061





More information about the cfe-commits mailing list