From de803468291ae96f7c3900247364aa295fe1d9a1 Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Fri, 10 Sep 2021 11:46:33 +0200 Subject: [PATCH] QByteDataBuffer::getChar() - assert that buffer is not empty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Found by CodeChecker. The getChar() method can return a garbage value if called on an empty buffer. Considering that QByteDataBuffer is an internal class and that there seems to be no current usage of this method, just add a Q_ASSERT to make sure that the buffer is not empty. Task-number: QTBUG-96303 Pick-to: 6.2 Change-Id: Iab0aee596aabafe999996f83177ca8bba16a58b6 Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Ievgenii Meshcheriakov Reviewed-by: Edward Welbourne --- src/corelib/text/qbytedata_p.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/corelib/text/qbytedata_p.h b/src/corelib/text/qbytedata_p.h index 77f351cbb4..3c36085021 100644 --- a/src/corelib/text/qbytedata_p.h +++ b/src/corelib/text/qbytedata_p.h @@ -244,6 +244,8 @@ public: inline char getChar() { + Q_ASSERT_X(!isEmpty(), "QByteDataBuffer::getChar", + "Cannot read a char from an empty buffer!"); char c; read(&c, 1); return c;