QByteDataBuffer::getChar() - assert that buffer is not empty

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 <marten.nordheim@qt.io>
Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
bb10
Ivan Solovev 2021-09-10 11:46:33 +02:00
parent a7fa677fc2
commit de80346829
1 changed files with 2 additions and 0 deletions

View File

@ -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;