From ecdbaf99a11b8c42632e6cb9786d68464aacc7ec Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Thu, 3 May 2018 20:13:35 +0200 Subject: 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 --- src/corelib/tools/qcontiguouscache.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/corelib') 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::detach_helper() template void QContiguousCache::setCapacity(int asize) { + Q_ASSERT(asize >= 0); if (asize == d->alloc) return; detach(); @@ -285,6 +286,7 @@ inline QContiguousCacheData *QContiguousCache::allocateData(int aalloc) template QContiguousCache::QContiguousCache(int cap) { + Q_ASSERT(cap >= 0); d = allocateData(cap); d->ref.store(1); d->alloc = cap; -- cgit v1.2.3