[cfe-commits] r50012 - /cfe/trunk/lib/Analysis/ExplodedGraph.cpp

Ted Kremenek kremenek at apple.com
Sun Apr 20 16:54:24 PDT 2008


Author: kremenek
Date: Sun Apr 20 18:54:24 2008
New Revision: 50012

URL: http://llvm.org/viewvc/llvm-project?rev=50012&view=rev
Log:
Fix improper dereference of end() iterator.  Patch by Argiris Kirtzidis!

Modified:
    cfe/trunk/lib/Analysis/ExplodedGraph.cpp

Modified: cfe/trunk/lib/Analysis/ExplodedGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ExplodedGraph.cpp?rev=50012&r1=50011&r2=50012&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/ExplodedGraph.cpp (original)
+++ cfe/trunk/lib/Analysis/ExplodedGraph.cpp Sun Apr 20 18:54:24 2008
@@ -80,8 +80,11 @@
   
   if (getKind() == Size1)
     return (ExplodedNodeImpl**) (getPtr() ? &P+1 : NULL);
-  else
-    return const_cast<ExplodedNodeImpl**>(&*(getVector(getPtr()).end()));
+  else {
+    // Dereferencing end() is undefined behaviour. The vector is not empty, so
+    // we can dereference the last elem (end()-1) and then add 1 to the result.
+    return const_cast<ExplodedNodeImpl**>(&*(getVector(getPtr()).end()-1)) + 1;
+  }
 }
 
 ExplodedNodeImpl::NodeGroup::~NodeGroup() {





More information about the cfe-commits mailing list