diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2018-10-23 20:07:45 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2018-10-23 20:07:45 +0000 |
commit | 5ac28a0cfda2c5f620886ace6f3b882e2e9a571d (patch) | |
tree | 977f058f782de3ca35000f6a9483299003436adc /libcxx/include/vector | |
parent | f86b8392d989560ffe58ff2eb15699a03e145c5f (diff) | |
download | bcm5719-llvm-5ac28a0cfda2c5f620886ace6f3b882e2e9a571d.tar.gz bcm5719-llvm-5ac28a0cfda2c5f620886ace6f3b882e2e9a571d.zip |
Off-by-one errors strike again. Thank goodness for ASAN and the bots.
llvm-svn: 345076
Diffstat (limited to 'libcxx/include/vector')
-rw-r--r-- | libcxx/include/vector | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/libcxx/include/vector b/libcxx/include/vector index 8ac7576ae7f..196ea70eafd 100644 --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -2606,8 +2606,13 @@ vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x) { 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_end(_ForwardIterator __first, _ForwardI { 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)); } |