diff options
author | Sona Kurazyan <sona.kurazyan@qt.io> | 2020-07-31 11:51:23 +0200 |
---|---|---|
committer | Sona Kurazyan <sona.kurazyan@qt.io> | 2020-08-04 19:52:22 +0200 |
commit | 8003ae79bfd72736b809805afbb7984c3431031e (patch) | |
tree | ac46396976bfb3c96341ed441b06f3c1b9ab6f85 /src/corelib/text/qbytearray.cpp | |
parent | 883f2dd81f8d85d52130aece540cdf9efa3d0069 (diff) |
Document the changed semantics when passing arrays to QByteArray methods
After adding QByteArrayView overloads of QByteArray methods that used
to take char*, the way of determining the length of passed fixed-sized
array data has changed, due to the QByteArraiyView's optimization to deduce
the length at compile time for arrays. Document the behavior and add a
changelog item.
[ChangeLog][QtCore][QByteArray] When passing fixed size C arrays to
QByteArray methods, the length of the data on which the method will operate
is determined by array size, and not by scanning for the first '\0'
terminator, as it was in Qt 5.
Task-number: QTBUG-85815
Change-Id: I11cba17d428791e06c9bd4c7a727b7bd6b6aec3c
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/text/qbytearray.cpp')
-rw-r--r-- | src/corelib/text/qbytearray.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index aee22edc6f..b5327280f9 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -847,6 +847,14 @@ QByteArray qUncompress(const uchar* data, int nbytes) such a pointer, without a length, will interpret it as this sequence of bytes. Such a sequence, by construction, cannot contain a '\\0' byte. + Take care when passing fixed size C arrays to QByteArray methods that accept + a QByteArrayView: the length of the data on which the method will operate is + determined by array size. A \c{char [N]} array will be handled as a view of + size \c{N-1}, on the expectation that the array is a string literal with a '\\0' + at index \c{N-1}. For example: + + \snippet code/src_corelib_text_qbytearray.cpp 54 + Other overloads accept a start-pointer and a byte-count; these use the given number of bytes, following the start address, regardless of whether any of them happen to be '\\0' bytes. In some cases, where there is no overload |