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

QByteArray::replace() unexpected behaviour

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P1: Critical
    • 4.7.1
    • 4.6.1
    • GUI: Text handling
    • None
    • Ubuntu Linux 8.0
    • d3f6e14066219a957f48d24e9f39d3d0c5a61f53

    Description

      QByteArray::replace() invoked on a raw char array break the array size to the first \0 encountered.
      That is not the expected behaviour than copying each char of the whole array.
      Being an array, not just a string, I expected the \0 doesn't break the QbyteArray size except for those string-like methods.
      I suggest to treat size() and length() method differently: size means the actual allocated space, length is for string-like evaluation.

      To reproduce the error, run the code below:

      void printArray(QByteArray& ba)
      {
      qDebug("\n");
      for (int i = 0 ; i < ba.size(); i++)
      qDebug("%x", (unsigned char)ba.at);
      }

      void main()
      {
      QByteArray qba;
      char testReplace[] = "abcde\0fghijk";

      qba.resize(sizeof(testReplace));
      qba.replace(0, 13, testReplace);
      printArray(qba);

      qba.resize(sizeof(testReplace));
      for(int i = 0; i < sizeof(testReplace); i++)
      qba[i] = testReplace[i];
      printArray(qba);
      }

      Attachments

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

        Activity

          People

            albisser Zeno Albisser
            prosa.com Giorgio Saviane
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes