diff -r b72c6db6890b -r 5dc02b23752f src/gui/painting/qdatabuffer_p.h --- a/src/gui/painting/qdatabuffer_p.h Wed Jun 23 19:07:03 2010 +0300 +++ b/src/gui/painting/qdatabuffer_p.h Tue Jul 06 15:10:48 2010 +0300 @@ -60,16 +60,20 @@ template class QDataBuffer { public: - QDataBuffer(int res = 64) + QDataBuffer(int res) { capacity = res; - buffer = (Type*) qMalloc(capacity * sizeof(Type)); + if (res) + buffer = (Type*) qMalloc(capacity * sizeof(Type)); + else + buffer = 0; siz = 0; } ~QDataBuffer() { - qFree(buffer); + if (buffer) + qFree(buffer); } inline void reset() { siz = 0; } @@ -81,7 +85,9 @@ inline Type &at(int i) { Q_ASSERT(i >= 0 && i < siz); return buffer[i]; } inline const Type &at(int i) const { Q_ASSERT(i >= 0 && i < siz); return buffer[i]; } + inline Type &last() { Q_ASSERT(!isEmpty()); return buffer[siz-1]; } inline const Type &last() const { Q_ASSERT(!isEmpty()); return buffer[siz-1]; } + inline Type &first() { Q_ASSERT(!isEmpty()); return buffer[0]; } inline const Type &first() const { Q_ASSERT(!isEmpty()); return buffer[0]; } inline void add(const Type &t) { @@ -90,6 +96,11 @@ ++siz; } + inline void pop_back() { + Q_ASSERT(siz > 0); + --siz; + } + inline void resize(int size) { reserve(size); siz = size; @@ -97,6 +108,8 @@ inline void reserve(int size) { if (size > capacity) { + if (capacity == 0) + capacity = 1; while (capacity < size) capacity *= 2; buffer = (Type*) qRealloc(buffer, capacity * sizeof(Type)); @@ -105,7 +118,12 @@ inline void shrink(int size) { capacity = size; - buffer = (Type*) qRealloc(buffer, capacity * sizeof(Type)); + if (size) + buffer = (Type*) qRealloc(buffer, capacity * sizeof(Type)); + else { + qFree(buffer); + buffer = 0; + } } inline void swap(QDataBuffer &other) {