Fixed bug in FoldingSetIteratorImpl where we did not correctly check if
authorTed Kremenek <kremenek@apple.com>
Fri, 15 Feb 2008 21:12:46 +0000 (21:12 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 15 Feb 2008 21:12:46 +0000 (21:12 +0000)
we had reached the "fake bucket" after the last bucket, allowing the iterator
in some cases to run off the end of the hashtable.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47178 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/FoldingSet.cpp

index 2d2279cefe5c1f24c6a4f49c9e99b92bbaff48a2..97d1f0d168957a27e2f04ab0926567f09203cca7 100644 (file)
@@ -326,7 +326,8 @@ FoldingSetImpl::Node *FoldingSetImpl::GetOrInsertNode(FoldingSetImpl::Node *N) {
 
 FoldingSetIteratorImpl::FoldingSetIteratorImpl(void **Bucket) {
   // Skip to the first non-null non-self-cycle bucket.
-  while (*Bucket == 0 || GetNextPtr(*Bucket) == 0)
+  while (*Bucket != reinterpret_cast<void*>(-1) &&
+         (*Bucket == 0 || GetNextPtr(*Bucket) == 0))
     ++Bucket;
   
   NodePtr = static_cast<FoldingSetNode*>(*Bucket);
@@ -345,7 +346,8 @@ void FoldingSetIteratorImpl::advance() {
     // Skip to the next non-null non-self-cycle bucket.
     do {
       ++Bucket;
-    } while (*Bucket == 0 || GetNextPtr(*Bucket) == 0);
+    } while (*Bucket != reinterpret_cast<void*>(-1) &&
+             (*Bucket == 0 || GetNextPtr(*Bucket) == 0));
     
     NodePtr = static_cast<FoldingSetNode*>(*Bucket);
   }