Skip to content

Commit

Permalink
Use system library function to byte swap VCT short channel name.
Browse files Browse the repository at this point in the history
Qt 6.1 added overloads to the QChar constructor that catch an int or
uint argument, and use an assert to validate that the passed value
fits in 16 bits. The current implementation calls the uint version of
the constructor, and will crash if it is ever passed a number outside
of the range 0-65535, which means passing the number -1 will cause a
crash.

Converting the exiting manual byte swap to use be16toh() serves two
purposes. First it guarantees that the result is a uint16_t and
therefore can't trigger the assert. Second, it should result in
correct values if this code is ever compiled on a big-endian system.
  • Loading branch information
linuxdude42 committed May 14, 2021
1 parent 5ad3029 commit e52e3ff
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion mythtv/libs/libmythtv/mpeg/atsctables.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
#define ATSC_TABLES_H

#include <cstdint> // uint32_t
#if HAVE_SYS_ENDIAN_H
#include <sys/endian.h>
#elif !CONFIG_DARWIN
#include <endian.h>
#else
#include <libkern/OSByteOrder.h>
#define be16toh(x) OSSwapBigToHostInt16(x)
#endif
#include <QString>

#include "atscdescriptors.h"
Expand Down Expand Up @@ -231,7 +239,7 @@ class MTV_PUBLIC VirtualChannelTable : public PSIPTable
const auto* ustr = reinterpret_cast<const unsigned short*>(m_ptrs[i]);
for (int j=0; j<7; j++)
{
QChar c((ustr[j]<<8) | (ustr[j]>>8));
QChar c(be16toh(ustr[j]));
if (c != QChar('\0')) str.append(c);
}
return str.simplified();
Expand Down

0 comments on commit e52e3ff

Please sign in to comment.