Skip to content

Commit

Permalink
QDataStream: prevent accidental streaming of pointers
Browse files Browse the repository at this point in the history
It doesn't make sense to stream a pointer, but it can happen by
accident because ds << ptr will select the operator<<(bool) overload.
Disable the out-stream operator for pointers by having a better match.

Reading a pointer from a QDataStream doesn't work, as a pointer
can't bind to e.g. a bool non-const reference.

[ChangeLog][QtCore][QDataStream] Streaming of arbitrary pointers
using QDataStream has been disabled. Note that such streaming happened
through the streaming operator for bool.

Change-Id: I4c98a33b52aae85e441f5a096efd404fbbf1e95f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
  • Loading branch information
dangelog committed Sep 17, 2023
1 parent b0ba5c7 commit 2fd4a86
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/corelib/serialization/qdatastream.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class Q_CORE_EXPORT QDataStream : public QIODeviceBase
QDataStream &operator<<(const char *str);
QDataStream &operator<<(char16_t c);
QDataStream &operator<<(char32_t c);
QDataStream &operator<<(const volatile void *) = delete;


QDataStream &readBytes(char *&, uint &len);
Expand Down

0 comments on commit 2fd4a86

Please sign in to comment.