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

QByteArrayView changes semantics for overloads that previously took char*

    XMLWordPrintable

Details

    • Task
    • Resolution: Done
    • P2: Important
    • None
    • 6.0.0
    • None
    • All

    Description

      I have code like this:

      struct Something {
          char name[8];
      };
      
      Something mappings[] {
          { "123" },
          { "1234567" },
      };
      // ...
      
      bool checkThing(const QByteArray &str)
      {    
          for (const auto &mapping : mappings) {
              // mapping.name gets converted to a QByteArrayView
              if (str.compare(mapping.name, Qt::CaseInsensitive) == 0)
                  return true;
          }
          return false;
      }
      
      // ...
      
      checkThing("123"); //  Always returns false because the QByteArrayView is larger
      checkThing("1234567");

      Which unfortunately fails after the merge / port to QByteArrayView due to it taking the size of the array minus 1. So even if I only use 3 of the characters it will still be comparing as if it was 7. While my code isn't in use anywhere so nothing is affected right now I'm sure someone else is not so lucky.

      Attachments

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

        Activity

          People

            sonakur Sona Kurazyan
            manordheim MÃ¥rten Nordheim
            Maurice Kalinowski Maurice Kalinowski
            Alex Blasche Alex Blasche
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes