summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qcontiguouscache.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2012-09-25 16:30:48 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-19 07:50:29 +0200
commit320c4e31e124f99601399d00935362b587c77510 (patch)
treec2f66d1e11284fc7e9167d6a1cdf241da4500b60 /src/corelib/tools/qcontiguouscache.h
parentc4b2d77f40a42a67480bb49aa63b0953c80c024a (diff)
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 <giuseppe.dangelo@kdab.com> Reviewed-by: Ian Walters <ian@walters.id.au> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qcontiguouscache.h')
-rw-r--r--src/corelib/tools/qcontiguouscache.h6
1 files changed, 6 insertions, 0 deletions
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<T>::freeData(Data *x)
template <typename T>
void QContiguousCache<T>::append(const T &value)
{
+ if (!d->alloc)
+ return; // zero capacity
detach();
if (QTypeInfo<T>::isComplex) {
if (d->count == d->alloc)
@@ -362,6 +364,8 @@ void QContiguousCache<T>::append(const T &value)
template<typename T>
void QContiguousCache<T>::prepend(const T &value)
{
+ if (!d->alloc)
+ return; // zero capacity
detach();
if (d->start)
d->start--;
@@ -385,6 +389,8 @@ template<typename T>
void QContiguousCache<T>::insert(int pos, const T &value)
{
Q_ASSERT_X(pos >= 0 && pos < INT_MAX, "QContiguousCache<T>::insert", "index out of range");
+ if (!d->alloc)
+ return; // zero capacity
detach();
if (containsIndex(pos)) {
if (QTypeInfo<T>::isComplex) {