A memory request of that size will always fail on a regular computer...
I am not sure, but QVector should assert when the allocation fails.
Are you sure it is a seg fault and not an assert?
A memory request of that size will always fail on a regular computer...
I am not sure, but QVector should assert when the allocation fails.
Are you sure it is a seg fault and not an assert?
1. I especially selected such size to demonstrate the problem. But actually it can happen with any size under low memory conditions in OS.
2. Will assertion help in release mode? I doubt.
After short debug session I found that it crashes right in QVector's constructor:
template <typename T>
inline QVectorData *QVector<T>::malloc(int aalloc)
{
return static_cast<QVectorData *>(qMalloc(sizeof(Data) + (aalloc - 1) * sizeof(T)));
}
template <typename T>
QVector<T>::QVector(int asize)
{
p = malloc(asize);
d->ref.init(1);
d->alloc = d->size = asize;
d->sharable = true;
d->capacity = false;
if (QTypeInfo<T>::isComplex) {
T* b = d->array;
T* i = d->array + d->size;
while (i != b)
new (--i) T;
} else {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
qMemSet(d->array, 0, asize * sizeof(T)); // place where crash actually occurs
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}
}
Bookmarks