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

QByteArray("").toHex() returns null QByteArray()

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P3: Somewhat important
    • None
    • 5.9, 5.12.5, 5.13.2
    • Core: Other
    • None
    • All

    Description

      Starting from Qt 5.9, when QByteArray::toHex(char separator) was introduced, the special case when the size of the input QByteArray is zero returns a null QByteArray.

      Thus, QByteArray("").toHex().isNull() is true, while I really expect it to be false. I don't think this is intended.

      The commit which introduced this kind of breaking change is 615027129d3d5e12a6e2f5d02d2af8320cc58ea7.

      I think if we handle the special case of an empty QByteArray, so should we handle a null input too, and return an empty / null result respectively.

      Interestingly, there are test cases which test exactly these cases: null should stay null and empty should stay empty. But these test cases succeed since an empty (non-null) QByteArray compares equal to a null QByteArray().

      In general: The documentation tells us that Qt distinguishes between a null and empty QByteArray for historical reasons, however, if this is the case, the documentation of functions which behave like this should document this behavior (i.e. "If this is empty, a null QByteArray is returned" or the like). It is not clear if this is "correct behavior".

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            leemes Sebastian Lehmann
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes