From 74098981bd42e6bc135c22506e5a910e37544406 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Tue, 5 Sep 2023 15:01:05 +0300 Subject: [PATCH] QDataStream: clarify QDataStream::operator>>(char *&s) API docs The wording was slightly ambiguous giving readers the idea that it will scan for a \0 terminator in the data; however what actually happens is that readBytes() gets the length of the string from a quint32 in the stream right before the data, and readBytes() always adds a null-terminator. Fixes: QTBUG-3287 Pick-to: 6.6 6.5 6.2 5.15 Change-Id: Ie22500a9c191ffd590a6b57babeb67577c24dddb Reviewed-by: Thiago Macieira --- src/corelib/serialization/qdatastream.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/corelib/serialization/qdatastream.cpp b/src/corelib/serialization/qdatastream.cpp index 15b607b0e03..7bb16645c9d 100644 --- a/src/corelib/serialization/qdatastream.cpp +++ b/src/corelib/serialization/qdatastream.cpp @@ -962,10 +962,11 @@ QDataStream &QDataStream::operator>>(double &f) /*! \overload - Reads the '\\0'-terminated string \a s from the stream and returns - a reference to the stream. + Reads string \a s from the stream and returns a reference to the stream. - The string is deserialized using \c{readBytes()}. + The string is deserialized using \c{readBytes()} where the serialization + format is a \c quint32 length specifier first, followed by that many bytes + of data. The resulting string is always '\\0'-terminated. Space for the string is allocated using \c{new []} -- the caller must destroy it with \c{delete []}.