From 591b3ac055ba1a349962a19b91ad388dcdc3ecb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Mon, 22 Sep 2014 17:13:02 +0800 Subject: [PATCH] bug fix --- TinySTL/Vector.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/TinySTL/Vector.h b/TinySTL/Vector.h index e900db0..aa1eb59 100644 --- a/TinySTL/Vector.h +++ b/TinySTL/Vector.h @@ -151,7 +151,7 @@ namespace TinySTL{ void destroyAndDeallocateAll(){ if (capacity() != 0){ dataAllocator::destroy(start_, finish_); - dataAllocator::deallocate(start_, endOfStorage_ - start_); + dataAllocator::deallocate(start_, capacity()); } } void allocateAndFillN(const size_type n, const value_type& value){ @@ -181,10 +181,10 @@ namespace TinySTL{ template void reallocateAndCopy(iterator position, InputIterator first, InputIterator last); void reallocateAndFillN(iterator position, const size_type& n, const value_type& val); - difference_type getNewCapacity(difference_type len)const{ - difference_type oldCapacity = endOfStorage_ - start_; - oldCapacity = oldCapacity ? oldCapacity : 1; - difference_type newCapacity = oldCapacity + std::max(oldCapacity, len); + size_type getNewCapacity(size_type len)const{ + size_type oldCapacity = endOfStorage_ - start_; + auto res = std::max(oldCapacity, len); + size_type newCapacity = (oldCapacity != 0 ? (oldCapacity + res) : 1); return newCapacity; } };// end of class vector @@ -294,6 +294,7 @@ namespace TinySTL{ template template void vector::insert_aux(iterator position, Integer n, Integer value, std::true_type){ + assert(n != 0); difference_type locationLeft = endOfStorage_ - finish_; // the size of left storage difference_type locationNeed = n;