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

QBitArray::count breaks after bitwise opererations

    XMLWordPrintable

Details

    • Windows
    • 8ac57ff6b (dev), cb517bd2e (6.8), 05f0c6ca0 (6.7)

    Description

      To replicate:

          QBitArray bitArrayAllOn(20, true);
          QBitArray bitArrayHalfAll(20, false);
      
          // Set every odd index to ON
          for (int i = 0; i < bitArrayHalfAll.size(); ++i) {
              bitArrayHalfAll.setBit(i, (i % 2));
          }
          
          // Expect result not to change and be 10 on, 10 off. 
          bitArrayHalfAll = bitArrayAllOn & bitArrayHalfAll;
          
          // Acutall result is size 20, on 15, off 5.
          qDebug() << "Size      :" << bitArrayHalfAll.size();
          qDebug() << "On count  :" << bitArrayHalfAll.count(true);
          qDebug() << "Off count :" << bitArrayHalfAll.count(false);
          
          // Work around I found that might help narrow down the issue.
          bitArrayHalfAll.resize(bitArrayHalfAll.size());
          
          // After resizing result is what is expected, size 20, 10 on, 10 off
          qDebug() << "Size      :" << bitArrayHalfAll.size();
          qDebug() << "On count  :" << bitArrayHalfAll.count(true);
          qDebug() << "Off count :" << bitArrayHalfAll.count(false);
      

       

      Output:

          Size      : 20
          On count  : 15
          Off count : 5
          Size      : 20
          On count  : 10
          Off count : 10
      

      The above code creates two QBitArrays, one with all on bits and the other with half on.

      When using bitwise & between the to arrays, we can see the result is incorrect. It should still have an on count on 10 out of 20 bits. This seems to be an issue with the classes internal size as calling resize on the bitarray fixes the result.

       

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            chris_gribble Chris Gribble
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes