diff options
| author | Vitaly Buka <vitalybuka@google.com> | 2018-04-13 18:41:52 +0000 |
|---|---|---|
| committer | Vitaly Buka <vitalybuka@google.com> | 2018-04-13 18:41:52 +0000 |
| commit | 753e99df6ddd1d332186b4f444fdade647d7a1a9 (patch) | |
| tree | d9e41c2b3b43b15f22255aa65bbcfa3ebb0173c9 | |
| parent | 63ee534ab10b7ece326bfb6c0a5011bd40895e83 (diff) | |
| download | bcm5719-llvm-753e99df6ddd1d332186b4f444fdade647d7a1a9.tar.gz bcm5719-llvm-753e99df6ddd1d332186b4f444fdade647d7a1a9.zip | |
[sanitizer] Fix __sanitizer::Vector::Resize vector
Implemented downsizing
Patch by Oleg Doronin
Reviewers: kcc, vitalybuka
Reviewed By: kcc, vitalybuka
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D45605
llvm-svn: 330049
| -rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_vector.h | 4 | ||||
| -rw-r--r-- | compiler-rt/lib/sanitizer_common/tests/sanitizer_vector_test.cc | 9 |
2 files changed, 13 insertions, 0 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_vector.h b/compiler-rt/lib/sanitizer_common/sanitizer_vector.h index 25cfeed35f2..0632ccce262 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_vector.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_vector.h @@ -82,6 +82,10 @@ class Vector { 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++) diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_vector_test.cc b/compiler-rt/lib/sanitizer_common/tests/sanitizer_vector_test.cc index bdcab7dd7f8..59fbf39685b 100644 --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_vector_test.cc +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_vector_test.cc @@ -39,4 +39,13 @@ TEST(Vector, Stride) { } } +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 |

