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

Oleg Doronin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 12 19:04:21 PDT 2018


dorooleg created this revision.
dorooleg added a reviewer: dvyukov.
Herald added subscribers: Sanitizers, llvm-commits, kubamracek.

When resize is done in smaller side need to move the pointer end

  Vector<int> v;
  v.PushBack(1);
  v.PushBack(2);
  v.Size(); // 1
  v.Resize(1);
  v.Size() // 2 but should be 1


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D45605

Files:
  sanitizer_common/sanitizer_vector.h


Index: sanitizer_common/sanitizer_vector.h
===================================================================
--- sanitizer_common/sanitizer_vector.h
+++ sanitizer_common/sanitizer_vector.h
@@ -95,8 +95,10 @@
   T *last_;
 
   void EnsureSize(uptr size) {
-    if (size <= Size())
+    if (size <= Size()) {
+      end_ = begin_ + size;
       return;
+    }
     if (size <= (uptr)(last_ - begin_)) {
       end_ = begin_ + size;
       return;


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


More information about the llvm-commits mailing list