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

QString::fromLatin1(const QByteArray&) incorrectly handles zero-filled QByteArray

    XMLWordPrintable

Details

    • 08775e4bd745276bcc6a5a9fdc4bed7aca225112

    Description

      In previous Qt version passing of non-empty QByteArray filled with zeroes into QString::fromLatin1 results into empty QString.
      For example this code worked correctly in previous Qt release and doesn't work in Qt 5.6 beta:

      // modifies data filling it's contents
      void GetAnsiString(char* data, size_t sz);
      
      QByteArray buf(1024, Qt::Uninitialized);
      GetAnsiString(buf.data(), buf.size());
      QString str = QString::fromLatin1(buf);
      if ( ! str.isEmpty() )
      {
      //...
      }
      

      The source of the problem is this commit which changed the behaviour of fromLatin1(QByteArray): https://codereview.qt-project.org/#/c/11530/1

      Currently the calls QString::fromLatin1(buf) and QString::fromLatin1(buf.data()) will lead to different results in case of buf contains zeroes.

      At least this should be documented.
      But, IMHO, it's not a good approach to break existing functionality and even make it inconsistent. If someone would like to have a method which handles zeroes inside a buffer then a new method with suitable name should be created.

      Link to the issue with a decision to not handle buffers with zeroes inside: https://bugreports.qt.io/browse/QTBUG-38553

      Attachments

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

        Activity

          People

            laknoll Lars Knoll
            ailin Aleksei Ilin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes