[libcxx] r345076 - Off-by-one errors strike again. Thank goodness for ASAN and the bots.
Marshall Clow
mclow.lists at gmail.com
Tue Oct 23 13:07:46 PDT 2018
Author: marshall
Date: Tue Oct 23 13:07:45 2018
New Revision: 345076
URL: http://llvm.org/viewvc/llvm-project?rev=345076&view=rev
Log:
Off-by-one errors strike again. Thank goodness for ASAN and the bots.
Modified:
libcxx/trunk/include/vector
Modified: libcxx/trunk/include/vector
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/vector?rev=345076&r1=345075&r2=345076&view=diff
==============================================================================
--- libcxx/trunk/include/vector (original)
+++ libcxx/trunk/include/vector Tue Oct 23 13:07:45 2018
@@ -2606,8 +2606,13 @@ vector<bool, _Allocator>::__construct_at
{
size_type __old_size = this->__size_;
this->__size_ += __n;
- if (__old_size == 0 || (__old_size / __bits_per_word) != (this->__size_ / __bits_per_word))
- this->__begin_[this->__size_ / __bits_per_word] = __storage_type(0);
+ if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word))
+ {
+ if (this->__size_ <= __bits_per_word)
+ this->__begin_[0] = __storage_type(0);
+ else
+ this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
+ }
_VSTD::fill_n(__make_iter(__old_size), __n, __x);
}
@@ -2622,8 +2627,13 @@ vector<bool, _Allocator>::__construct_at
{
size_type __old_size = this->__size_;
this->__size_ += _VSTD::distance(__first, __last);
- if (__old_size == 0 || (__old_size / __bits_per_word) != (this->__size_ / __bits_per_word))
- this->__begin_[this->__size_ / __bits_per_word] = __storage_type(0);
+ if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word))
+ {
+ if (this->__size_ <= __bits_per_word)
+ this->__begin_[0] = __storage_type(0);
+ else
+ this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
+ }
_VSTD::copy(__first, __last, __make_iter(__old_size));
}
More information about the libcxx-commits
mailing list