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

QString at() and operator[], assertions need change

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 4.8.0
    • None
    • Windows, Linux... 32 and 64

    Description

      Currently the assertion is:
      Q_ASSERT(uint < uint(size()))

      With this the '\0' cannot retrieved with at() or []
      will be good to change this to:
      Q_ASSERT(uint <= uint(size()))

      Ex:
      QString echoChar(QChar c)

      { if (c == QChar(0)) return "<NUL>"; else ... return QString(c); }

      QString test("01234"); // size() == 5

      qDebug() << "test[0]: " << echoChar(test[0]); // output: test[0]: "0"
      qDebug() << "test[1]: " << echoChar(test[1]); // output: test[1]: "1"
      qDebug() << "test[2]: " << echoChar(test[2]); // output: test[2]: "4"
      qDebug() << "test[5]: " << echoChar(test[5]); // expected output: test[5]: "NUL",
      but here the assertion will be fired!

      I fink that code are 'copied' from QByteArray that doen't have null terminate char.

      Attachments

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

        Activity

          People

            biochimia João Abecasis
            israelins85 Israel Lins Albuquerque
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes