Skip to content

Commit

Permalink
qt6: Fix parsing when reading from the command socket.
Browse files Browse the repository at this point in the history
After converting the byte array to a string, qt5 ignored the NUL
character at the end when it was asked to trim white space from the
string. Qt6 does care about the NUL (and doesn't consider it white
space) so nothing is trimmed.  The QString::toInt function fails if it
sees any character other than a digit, thus it would always fail on
Qt6 where it had worked on Qt5.  Removing the padding byte at the end
of the array allows the same code to work on both version of Qt.
  • Loading branch information
linuxdude42 committed Mar 28, 2021
1 parent c76d430 commit 27aa210
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions mythtv/libs/libmythbase/mythsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ void MythSocket::ReadStringListReal(
m_tcpSocket->waitForReadyRead(50);
}

QByteArray sizestr(8 + 1, '\0');
QByteArray sizestr(8, '\0');
if (m_tcpSocket->read(sizestr.data(), 8) < 0)
{
LOG(VB_GENERAL, LOG_ERR, LOC +
Expand All @@ -844,14 +844,16 @@ void MythSocket::ReadStringListReal(
}

QString sizes = sizestr;
int btr = sizes.trimmed().toInt();
bool ok { false };
int btr = sizes.trimmed().toInt(&ok);

if (btr < 1)
{
int pending = m_tcpSocket->bytesAvailable();
LOG(VB_GENERAL, LOG_ERR, LOC +
QString("Protocol error: '%1' is not a valid size "
"prefix. %2 bytes pending.")
QString("Protocol error: %1'%2' is not a valid size "
"prefix. %3 bytes pending.")
.arg(ok ? "" : "(parse failed) ")
.arg(sizestr.data()).arg(pending));
ResetReal();
return;
Expand Down

0 comments on commit 27aa210

Please sign in to comment.