From 320c4e31e124f99601399d00935362b587c77510 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 25 Sep 2012 16:30:48 +0200 Subject: Make QContiguousCache with zero capacity not crash These containers don't make sense and will just result in no action being taken (all items added will simply be discarded), but it shouldn't crash due to a division by zero. Update the documentation to explain the fact. Task-number: QTBUG-27339 Change-Id: Ib9acf5c0a9a826e6853e7beaf5e56511fde98dc6 Reviewed-by: Giuseppe D'Angelo Reviewed-by: Ian Walters Reviewed-by: Thiago Macieira --- src/corelib/tools/qcontiguouscache.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/corelib/tools/qcontiguouscache.h') diff --git a/src/corelib/tools/qcontiguouscache.h b/src/corelib/tools/qcontiguouscache.h index 8713a3407a..e1cc65f10a 100644 --- a/src/corelib/tools/qcontiguouscache.h +++ b/src/corelib/tools/qcontiguouscache.h @@ -341,6 +341,8 @@ void QContiguousCache::freeData(Data *x) template void QContiguousCache::append(const T &value) { + if (!d->alloc) + return; // zero capacity detach(); if (QTypeInfo::isComplex) { if (d->count == d->alloc) @@ -362,6 +364,8 @@ void QContiguousCache::append(const T &value) template void QContiguousCache::prepend(const T &value) { + if (!d->alloc) + return; // zero capacity detach(); if (d->start) d->start--; @@ -385,6 +389,8 @@ template void QContiguousCache::insert(int pos, const T &value) { Q_ASSERT_X(pos >= 0 && pos < INT_MAX, "QContiguousCache::insert", "index out of range"); + if (!d->alloc) + return; // zero capacity detach(); if (containsIndex(pos)) { if (QTypeInfo::isComplex) { -- cgit v1.2.3