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

QVector and QByteArray behave weird when size nearly INT_MAX on 64Bit machines

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Incomplete
    • Icon: Not Evaluated Not Evaluated
    • None
    • 4.8.6, 5.3.2
    • None
    • Windows 7 64-Bit, VS2010 with Qt4.8.6, QtCreator with 5.3.2

      Following the 64Bit issue in storage QTBUG-32999 the following code is not behaving as expected:

      QByteArray blah;
      blah.fill( ' ', INT_MAX );	// ok
      blah.append( "hello" );		// makes size negative (no exception/warning in Qt4, ASSERT "alloc/extra" in 5 -> "ignore")
      QByteArray ba = blah.mid( INT_MAX - 1, 5 ); // empty array (no warning either)
      uint s = blah.size();   // would be the correct size
      int si = blah.size();
      blah.remove( 0, INT_MAX - 5 ); // size still negative in Qt4, 0 in Qt5
      
      QVector<char> v;
      v.resize( INT_MAX / 2 - 16 );	// throws std::bad_alloc in Qt4, qAllocMore: "Requested size is too large!" in Qt5
      v.fill( 'a', INT_MAX/2 - 16 );	// throws std::bad_alloc in Qt4, qAllocMore: "Requested size is too large!" in Qt5
      v.resize( INT_MAX / 2 - 24 );	// ok in both
      v.resize( INT_MAX / 2 - 17 );	// ok in Qt4, qAllocMore: "Requested size is too large!" in Qt5
      v.resize( INT_MAX / 2 - 16 );	// ok in Qt4 (???), qAllocMore: "Requested size is too large!" in Qt5
      
      v.fill( 'a' );		// ok
      v.append( 'b' );	// ok
      v.append( 'c' );	// qAllocMore: "Requested size is too large!" (if resized to INT_MAX/2-16 or -24 in Qt5)
      v.append( 'd' );	// qAllocMore: "Requested size is too large!" (if resized to INT_MAX/2-17)
      char c = v.last();
      

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

            thiago Thiago Macieira
            soukupmi Michael Soukup
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes