summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-05-03 20:13:35 +0200
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-05-04 04:49:33 +0000
commitecdbaf99a11b8c42632e6cb9786d68464aacc7ec (patch)
treeb4bf3288d6a162c6727f58b3751c17f4881880f8 /src/corelib
parente28ae083d2ba69406bf444f951b6c820c5aaf4f4 (diff)
QContiguousCache: add assertion to avoid negative capacity
The ctor of QContiguousCache and setCapacity are accepting negative values for the capacity. While this should not be done it can happen by accident. Therefore add Q_ASSERT to ensure a positive value. Task-number: QTBUG-19700 Change-Id: I7458100c07c687cdeaebe86400343d79b5a6330a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/tools/qcontiguouscache.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/corelib/tools/qcontiguouscache.h b/src/corelib/tools/qcontiguouscache.h
index 18facf7e42..faa7263d6b 100644
--- a/src/corelib/tools/qcontiguouscache.h
+++ b/src/corelib/tools/qcontiguouscache.h
@@ -211,6 +211,7 @@ void QContiguousCache<T>::detach_helper()
template <typename T>
void QContiguousCache<T>::setCapacity(int asize)
{
+ Q_ASSERT(asize >= 0);
if (asize == d->alloc)
return;
detach();
@@ -285,6 +286,7 @@ inline QContiguousCacheData *QContiguousCache<T>::allocateData(int aalloc)
template <typename T>
QContiguousCache<T>::QContiguousCache(int cap)
{
+ Q_ASSERT(cap >= 0);
d = allocateData(cap);
d->ref.store(1);
d->alloc = cap;