From cbc6ee0eb9ef42c7024fa527bb94ac89953709a6 Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Tue, 30 Jan 2024 11:35:31 +0100 Subject: Deprecate QDataStream::readBytes(char *&, uint &) instead of removing it We cannot remove the overload using QT_REMOVED_SINCE, because a qint64 lvalue in the new overload will not bind to an uint& parameter, so the old code would not compile. Deprecate the old overload, and add a unit-test that makes sure that it still behaves correctly. This commit also introduces the new deprecation macros that are required to do the deprecation in Qt 6.11. Amends fd48ce0b73c74dafd5db27bc1f2752ef665df7ef Found in 6.7 API review Pick-to: 6.7 Change-Id: I02893bfbe040df736f8e746384e0261a0f0041d3 Reviewed-by: Edward Welbourne Reviewed-by: Qt CI Bot Reviewed-by: Thiago Macieira --- src/corelib/serialization/qdatastream.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/corelib/serialization/qdatastream.cpp') diff --git a/src/corelib/serialization/qdatastream.cpp b/src/corelib/serialization/qdatastream.cpp index dcfa292f154..7d25a04978f 100644 --- a/src/corelib/serialization/qdatastream.cpp +++ b/src/corelib/serialization/qdatastream.cpp @@ -1037,7 +1037,29 @@ QDataStream &QDataStream::operator>>(char32_t &c) return *this; } +#if QT_DEPRECATED_SINCE(6, 11) + +/* + \deprecated [6.11] Use an overload that takes qint64 length instead. +*/ +QDataStream &QDataStream::readBytes(char *&s, uint &l) +{ + qint64 length = 0; + (void)readBytes(s, length); + if (length != qint64(uint(length))) { + setStatus(SizeLimitExceeded); // Cannot store length in l + delete[] s; + l = 0; + return *this; + } + l = uint(length); + return *this; +} + +#endif // QT_DEPRECATED_SINCE(6, 11) + /*! + \since 6.7 Reads the buffer \a s from the stream and returns a reference to the stream. -- cgit v1.2.3