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

Empty QBitArray behaves badly.

    XMLWordPrintable

Details

    • 873ae53d47b34e51c0e44303499fad23737f9e5b

    Description

      The problem arised this way:

      QBitArray a;
      a.resize (0);
      qDebug () << a.count () << a.count (true) << a.count (false);
      

      Expected and usual result is 0 0 0, but sometimes it is: 0 1 -1

      To me, the reason is this (qbitarray.cpp):

      void QBitArray::resize(int size)
      {
          if (!size) {
              d.resize(0); /* QByteArray is resized to 0 */
      ....
      }
      

      And than:

      int QBitArray::count(bool on) const
      {
          int numBits = 0;
          int len = size();
          const quint8 *bits = reinterpret_cast<const quint8 *>(d.data()) + 1;  
         /* bits now points past the end of allocated memory */
      .......
      
          while (len >= 0) {
              if (bits[len / 8] & (1 << ((len - 1) & 7)))  /* here we access some unknown memory */
                  ++numBits;
              --len;
          }
      
          return on ? numBits : size() - numBits;
      }
      

      Attachments

        For Gerrit Dashboard: QTBUG-11625
        # Subject Branch Project Status CR V

        Activity

          People

            thiago Thiago Macieira
            cerber Artur Brugeman
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes