From 7ff0dfab1bcda8904a52c5682fe2ed4c52c5292e Mon Sep 17 00:00:00 2001 From: Adam Majer Date: Fri, 12 Sep 2014 11:05:15 -0500 Subject: [PATCH] Use stack instead of broken usage of QByteBuffer The internal buffer should not be used blindly when reading Frame::HEADER_SIZE, as it is error prone and adds nothing over reading on the stack (and it's only 7 bytes). There are places in this class where buffer.clear() is called. --- src/qamqpclient.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/qamqpclient.cpp b/src/qamqpclient.cpp index e61d8d0..3d0df6c 100644 --- a/src/qamqpclient.cpp +++ b/src/qamqpclient.cpp @@ -31,7 +31,6 @@ ClientPrivate::ClientPrivate(Client *q) error(QAMQP::NoError), q_ptr(q) { - buffer.reserve(Frame::HEADER_SIZE); } ClientPrivate::~ClientPrivate() @@ -190,8 +189,10 @@ void ClientPrivate::_q_socketError(QAbstractSocket::SocketError error) void ClientPrivate::_q_readyRead() { while (socket->bytesAvailable() >= Frame::HEADER_SIZE) { - char *headerData = buffer.data(); + char headerData[Frame::HEADER_SIZE]; socket->peek(headerData, Frame::HEADER_SIZE); + // FIXME: This is not the correct way of reading payloadSize + // gcc: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] const quint32 payloadSize = qFromBigEndian(*(quint32*)&headerData[3]); const qint64 readSize = Frame::HEADER_SIZE + payloadSize + Frame::FRAME_END_SIZE;