[PATCH] D45605: Resize vector have does not work correctly

Vitaly Buka via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 13 11:22:54 PDT 2018


vitalybuka updated this revision to Diff 142444.
vitalybuka added a comment.

Update description


Repository:
  rL LLVM

https://reviews.llvm.org/D45605

Files:
  compiler-rt/lib/sanitizer_common/sanitizer_vector.h
  compiler-rt/lib/sanitizer_common/tests/sanitizer_vector_test.cc


Index: compiler-rt/lib/sanitizer_common/tests/sanitizer_vector_test.cc
===================================================================
--- compiler-rt/lib/sanitizer_common/tests/sanitizer_vector_test.cc
+++ compiler-rt/lib/sanitizer_common/tests/sanitizer_vector_test.cc
@@ -39,4 +39,13 @@
   }
 }
 
+TEST(Vector, ResizeReduction) {
+  Vector<int> v;
+  v.PushBack(0);
+  v.PushBack(0);
+  EXPECT_EQ(v.Size(), 2);
+  v.Resize(1);
+  EXPECT_EQ(v.Size(), 1);
+}
+
 }  // namespace __sanitizer
Index: compiler-rt/lib/sanitizer_common/sanitizer_vector.h
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_vector.h
+++ compiler-rt/lib/sanitizer_common/sanitizer_vector.h
@@ -82,6 +82,10 @@
       return;
     }
     uptr old_size = Size();
+    if (size <= old_size) {
+      end_ = begin_ + size;
+      return;
+    }
     EnsureSize(size);
     if (old_size < size) {
       for (uptr i = old_size; i < size; i++)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45605.142444.patch
Type: text/x-patch
Size: 981 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180413/227b03d9/attachment.bin>


More information about the llvm-commits mailing list