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

Incorrect initialization of QBitArray from dense byte array

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: 5.12.4, 5.13.0
    • Fix Version/s: 5.12.5, 5.14.0 Alpha
    • Component/s: Core: Other
    • Labels:
      None
    • Platform/s:
      All
    • Commits:
      6ce9404a6e7ad6ba3ff37f6890fe400c643c3d52 (qt/qtbase/5.12)

      Description

      When initializing a QBitArray using function:

      static QBitArray fromBits(const char *data, qsizetype len);
      

      The resulting bit array isn't always properly initialized.

      I wrote an example where I have one byte but want to use only 5 bits.

      // Example code
      #include <QCoreApplication>
      #include <QBitArray>
      #include <stdio.h>
      
      int main(int argc, char* argv[])
      {
          QCoreApplication a(argc, argv);
          char c = 0xff;
          const int nbits = 5;
          const QBitArray ba = QBitArray::fromBits(&c, nbits);
      
          for(int b=0 ; b<nbits ; ++b)
              printf("%d ", ba.testBit(b) ? 1 : 0);
      
          fflush(stdout);
      
          return a.exec();
      }
      

      The above code produces the following result:

      1 1 1 0 0
      

      When in fact it should produce:

      1 1 1 1 1
      

      This happens always in the last byte of the array, I was able to reproduce this in arrays of several sizes, this example has one byte only for simplicity.

       

        Attachments

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

          Activity

            People

            • Assignee:
              thiago Thiago Macieira
              Reporter:
              ruisilva Rui Silva
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Gerrit Reviews

                There are no open Gerrit changes