Details
-
Bug
-
Resolution: Out of scope
-
Not Evaluated
-
None
-
4.5.3, 4.6.0
-
None
-
Win64, linux64
Description
This is mostly a problem on 64-bit platforms where we want to allocate space for large arrays.
QVector<int> v1; // empty QVector<int> v2; // empty, but shared null data with v1 v2.resize(2^30); // should work since less than INT_MAX, but fails with a thud
Problem is QVectorData::malloc(int sizeOfTypedData, int size, int sizeofT, QVectorData *init) multiplies size and sizeofT, subsequently blowing out INT_MAX before being implicitly cast to size_t when passed to qMalloc(). Either the parameter type of sizeofT should be size_t or the allocation size needs to be computed such that a value greater than INT_MAX can be passed to qMalloc() (using a temporary, for example).
A workaround is to call QVector<T>::detach() to get an unshared data copy, then resize(int). This code path uses qRealloc() for the large allocation and uses the sizeof operator directly.