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

QList::mid may result in all new lists being corrupted

    XMLWordPrintable

Details

    • 8befc4982a32752e48c82cacbed045e7336a3569

    Description

      Since Qt 4.7, QList::mid has been partially rewritten (surely for optimization reasons).
      However, when used with bad indices on an empty list, it can result in overwritting QListData::shared_null making new QLists unusable.
      In Qt 4.6, it returned an empty list because the loop was not entered when indices where wrong.
      Don't know why QList::mid has been rewritten but not QVector ??

      The following code reproduces the problem:
      #include <stdio.h>
      #include <QList>

      void main()
      {
      QList<int> indices;
      printf("NN1 = %d\n", indices.length());
      QList<int> ind2 = indices.mid(1,1);
      printf("NN2 = %d\n", ind2.length());
      QList<int> ind3;
      printf("NN3 = %d\n", ind3.length());
      }

      Will print out:
      $ ./aa.exe
      NN1 = 0
      NN2 = -1
      NN3 = -1

      All the lists are broken, and you're not so far from the crash (for example using foreach...), even if you use a completly different list in a different portion of the source.

      Attachments

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

        Activity

          People

            liaqi Liang Qi
            bfoucher Benjamin Foucher
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes