Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-6672

QVector<T>::resize(size) with shared data fails for large sizes less than 2^31-1

    XMLWordPrintable

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.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            stormols Marius Storm-Olsen
            pabakertx Patrick Baker
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes