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

Case-Sensitive QStringRef::compare() compares the first character after the end of the StringRef

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P1: Critical
    • 4.7.0
    • 4.5.3, 4.6.2
    • None
    • cd003bfcf9a05967893099e8948ba3d8f281aa7d

    Description

      If you do a case-sensitive comparison of a QStringRef and a QLatin1String, the comparison returns a value other than 0, even if the strings are equal.
      A comparison of QStrings works fine, because the character after the last character is '\0'

      QString string = QLatin1String("ThisIsATestString");
      QStringRef ref( &string, 0, 11 );

      // returns 83 ('S')
      ref.compare( QLatin1String("ThisIsATest") );

      // returns 0
      ref.compare( QLatin1String("ThisIsATestS") );

      The problem lies within QString::compare_helper(const QChar *data1, int length1, QLatin1String s2, Qt::CaseSensitivity cs)
      It would probably work, if the number of compared characters was reduced by 1 (const ushort *e = uc + length1 - 1, unless the comparison of the zero-character is mandatory for some cases.

      Attachments

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

        Activity

          People

            goffart Olivier Goffart (closed Nokia identity) (Inactive)
            mkrems Marcel Krems
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes