[PATCH] D27849: crash in MallocChecker

Devin Coughlin via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 16 10:52:17 PST 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL289970: [analyzer] Fix crash in MallocChecker. (authored by dcoughlin).

Changed prior to commit:
  https://reviews.llvm.org/D27849?vs=81751&id=81774#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27849

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  cfe/trunk/test/Analysis/out-of-bounds-new.cpp


Index: cfe/trunk/test/Analysis/out-of-bounds-new.cpp
===================================================================
--- cfe/trunk/test/Analysis/out-of-bounds-new.cpp
+++ cfe/trunk/test/Analysis/out-of-bounds-new.cpp
@@ -148,3 +148,9 @@
   int *buf = new int[s];
   buf[0] = 1; // no-warning
 }
+//Tests complex arithmetic
+//in new expression
+void test_dynamic_size2(unsigned m,unsigned n){
+  unsigned *U = nullptr;
+  U = new unsigned[m + n + 1];
+}
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -1026,8 +1026,7 @@
   ASTContext &AstContext = C.getASTContext();
   CharUnits TypeSize = AstContext.getTypeSizeInChars(ElementType);
 
-  if (Optional<DefinedOrUnknownSVal> DefinedSize =
-          ElementCount.getAs<DefinedOrUnknownSVal>()) {
+  if (ElementCount.getAs<NonLoc>()) {
     DefinedOrUnknownSVal Extent = Region->getExtent(svalBuilder);
     // size in Bytes = ElementCount*TypeSize
     SVal SizeInBytes = svalBuilder.evalBinOpNN(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27849.81774.patch
Type: text/x-patch
Size: 1158 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161216/8aef325e/attachment.bin>


More information about the cfe-commits mailing list