Bug 808679 - Add asserts for Vector::Range and Vector srcbeg <= srcend. r=Waldo

This commit is contained in:
Chris Peterson 2014-02-11 22:42:39 -08:00
parent d19818cc91
commit e912926be0

View File

@ -59,12 +59,14 @@ struct VectorImpl
{ {
/* Destroys constructed objects in the range [begin, end). */ /* Destroys constructed objects in the range [begin, end). */
static inline void destroy(T* begin, T* end) { static inline void destroy(T* begin, T* end) {
MOZ_ASSERT(begin <= end);
for (T* p = begin; p < end; ++p) for (T* p = begin; p < end; ++p)
p->~T(); p->~T();
} }
/* Constructs objects in the uninitialized range [begin, end). */ /* Constructs objects in the uninitialized range [begin, end). */
static inline void initialize(T* begin, T* end) { static inline void initialize(T* begin, T* end) {
MOZ_ASSERT(begin <= end);
for (T* p = begin; p < end; ++p) for (T* p = begin; p < end; ++p)
new(p) T(); new(p) T();
} }
@ -75,6 +77,7 @@ struct VectorImpl
*/ */
template<typename U> template<typename U>
static inline void copyConstruct(T* dst, const U* srcbeg, const U* srcend) { static inline void copyConstruct(T* dst, const U* srcbeg, const U* srcend) {
MOZ_ASSERT(srcbeg <= srcend);
for (const U* p = srcbeg; p < srcend; ++p, ++dst) for (const U* p = srcbeg; p < srcend; ++p, ++dst)
new(dst) T(*p); new(dst) T(*p);
} }
@ -85,6 +88,7 @@ struct VectorImpl
*/ */
template<typename U> template<typename U>
static inline void moveConstruct(T* dst, U* srcbeg, U* srcend) { static inline void moveConstruct(T* dst, U* srcbeg, U* srcend) {
MOZ_ASSERT(srcbeg <= srcend);
for (U* p = srcbeg; p < srcend; ++p, ++dst) for (U* p = srcbeg; p < srcend; ++p, ++dst)
new(dst) T(Move(*p)); new(dst) T(Move(*p));
} }
@ -144,6 +148,7 @@ struct VectorImpl<T, N, AP, ThisVector, true>
* *
* memset(begin, 0, sizeof(T) * (end-begin)); * memset(begin, 0, sizeof(T) * (end-begin));
*/ */
MOZ_ASSERT(begin <= end);
for (T* p = begin; p < end; ++p) for (T* p = begin; p < end; ++p)
new(p) T(); new(p) T();
} }
@ -157,6 +162,7 @@ struct VectorImpl<T, N, AP, ThisVector, true>
* *
* memcpy(dst, srcbeg, sizeof(T) * (srcend - srcbeg)); * memcpy(dst, srcbeg, sizeof(T) * (srcend - srcbeg));
*/ */
MOZ_ASSERT(srcbeg <= srcend);
for (const U* p = srcbeg; p < srcend; ++p, ++dst) for (const U* p = srcbeg; p < srcend; ++p, ++dst)
*dst = *p; *dst = *p;
} }
@ -391,13 +397,15 @@ class VectorBase : private AllocPolicy
friend class VectorBase; friend class VectorBase;
T* cur_; T* cur_;
T* end_; T* end_;
Range(T* cur, T* end) : cur_(cur), end_(end) {} Range(T* cur, T* end) : cur_(cur), end_(end) {
MOZ_ASSERT(cur <= end);
}
public: public:
Range() {} Range() {}
bool empty() const { return cur_ == end_; } bool empty() const { return cur_ == end_; }
size_t remain() const { return end_ - cur_; } size_t remain() const { return PointerRangeSize(cur_, end_); }
T& front() const { return *cur_; } T& front() const { MOZ_ASSERT(!empty()); return *cur_; }
void popFront() { MOZ_ASSERT(!empty()); ++cur_; } void popFront() { MOZ_ASSERT(!empty()); ++cur_; }
T popCopyFront() { MOZ_ASSERT(!empty()); return *cur_++; } T popCopyFront() { MOZ_ASSERT(!empty()); return *cur_++; }
}; };