[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:45:08 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL330049: [sanitizer] Fix __sanitizer::Vector::Resize vector (authored by vitalybuka, committed by ).
Herald added a subscriber: delcypher.
Changed prior to commit:
https://reviews.llvm.org/D45605?vs=142444&id=142449#toc
Repository:
rL LLVM
https://reviews.llvm.org/D45605
Files:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_vector.h
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_vector_test.cc
Index: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_vector_test.cc
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_vector_test.cc
+++ compiler-rt/trunk/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(), 2u);
+ v.Resize(1);
+ EXPECT_EQ(v.Size(), 1u);
+}
+
} // namespace __sanitizer
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_vector.h
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_vector.h
+++ compiler-rt/trunk/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.142449.patch
Type: text/x-patch
Size: 1019 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180413/5245304e/attachment.bin>
More information about the llvm-commits
mailing list