summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorZeno Albisser <zeno.albisser@nokia.com>2010-02-12 08:15:10 (GMT)
committerZeno Albisser <zeno.albisser@nokia.com>2010-02-15 12:17:08 (GMT)
commit81dae1c0f37ed0b9e4ec6bc1febad273391f518e (patch)
tree84ac8cf3769258c3e4964aef0769b99344fb85f1 /src
parent6c16e4ddd2f5397095ab892872b24bb717ee9147 (diff)
downloadQt-81dae1c0f37ed0b9e4ec6bc1febad273391f518e.zip
Qt-81dae1c0f37ed0b9e4ec6bc1febad273391f518e.tar.gz
Qt-81dae1c0f37ed0b9e4ec6bc1febad273391f518e.tar.bz2
Fix for using QContiguousCache with default constructor or capacity=0
Reviewed-by: Peter Hartmann
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qcontiguouscache.h35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/corelib/tools/qcontiguouscache.h b/src/corelib/tools/qcontiguouscache.h
index 1f7fdb2..aa5603d 100644
--- a/src/corelib/tools/qcontiguouscache.h
+++ b/src/corelib/tools/qcontiguouscache.h
@@ -221,22 +221,29 @@ void QContiguousCache<T>::setCapacity(int asize)
x.d->alloc = asize;
x.d->count = qMin(d->count, asize);
x.d->offset = d->offset + d->count - x.d->count;
- x.d->start = x.d->offset % x.d->alloc;
- T *dest = x.p->array + (x.d->start + x.d->count-1) % x.d->alloc;
- T *src = p->array + (d->start + d->count-1) % d->alloc;
+ if(asize)
+ x.d->start = x.d->offset % x.d->alloc;
+ else
+ x.d->start = 0;
+
int oldcount = x.d->count;
- while (oldcount--) {
- if (QTypeInfo<T>::isComplex) {
- new (dest) T(*src);
- } else {
- *dest = *src;
+ if(oldcount)
+ {
+ T *dest = x.p->array + (x.d->start + x.d->count-1) % x.d->alloc;
+ T *src = p->array + (d->start + d->count-1) % d->alloc;
+ while (oldcount--) {
+ if (QTypeInfo<T>::isComplex) {
+ new (dest) T(*src);
+ } else {
+ *dest = *src;
+ }
+ if (dest == x.p->array)
+ dest = x.p->array + x.d->alloc;
+ dest--;
+ if (src == p->array)
+ src = p->array + d->alloc;
+ src--;
}
- if (dest == x.p->array)
- dest = x.p->array + x.d->alloc;
- dest--;
- if (src == p->array)
- src = p->array + d->alloc;
- src--;
}
/* free old */
free(p);