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>bb10
parent
e28ae083d2
commit
ecdbaf99a1
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue