Skip to content

Commit

Permalink
tidy: Remove redundant casting. (qt5/qt6)
Browse files Browse the repository at this point in the history
This test "detects explicit type casting operations that involve the
same source and destination types, and subsequently recommend their
removal".

These changes were made for qt5 by the clang-tidy program.  They were
then adjusted manually so that they didn't break qt6 compilation.

https://clang.llvm.org/extra/clang-tidy/checks/readability/redundant-casting.html
  • Loading branch information
linuxdude42 committed Mar 26, 2024
1 parent 8dbf21d commit becf165
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 10 deletions.
6 changes: 5 additions & 1 deletion mythtv/libs/libmythbase/mythdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,11 @@ QString formatTime(std::chrono::milliseconds msecs, QString fmt)
if (match.hasMatch())
{
static constexpr std::array<int,4> divisor = {1000, 100, 10, 1};
int width = std::min(3, static_cast<int>(match.capturedLength()));
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
int width = std::min(3, match.capturedLength());
#else
int width = std::min(3LL, match.capturedLength());
#endif
int value = (msecs % 1s).count() / divisor[width];
QString text = StringUtil::intToPaddedString(value, width);
fmt.replace(match.capturedStart(), match.capturedLength(), text);
Expand Down
4 changes: 4 additions & 0 deletions mythtv/libs/libmythfreemheg/TokenGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,11 @@ void MHListGroup::Update(MHEngine *engine)
if (m_nLastCount - m_nLastFirstItem != m_itemList.size() - m_nFirstItem)
{
engine->EventTriggered(this, EventTailItems,
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
(m_itemList.size()) - m_nFirstItem);
#else
static_cast<int>(m_itemList.size()) - m_nFirstItem);
#endif
}

m_nLastCount = m_itemList.size();
Expand Down
4 changes: 4 additions & 0 deletions mythtv/libs/libmythfreemheg/TokenGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ class MHListGroup : public MHTokenGroup
void GetFirstItem(MHRoot *pResult, MHEngine */*engine*/) override // MHRoot
{ pResult->SetVariableValue(m_nFirstItem); }
void GetListSize(MHRoot *pResult, MHEngine */*engine*/) override // MHRoot
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
{ pResult->SetVariableValue(m_itemList.size()); }
#else
{ pResult->SetVariableValue(static_cast<int>(m_itemList.size())); }
#endif

protected:
// MHEG Internal attributes.
Expand Down
6 changes: 5 additions & 1 deletion mythtv/libs/libmythtv/HLS/httplivestreambuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,11 @@ class HLSStream
// not even size, pad with front 0
line.insert(2, QLatin1String("0"));
}
int padding = std::max(0, AES_BLOCK_SIZE - (static_cast<int>(line.size()) - 2));
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
int padding = std::max(0, AES_BLOCK_SIZE - (line.size() - 2));
#else
int padding = std::max(0LL, AES_BLOCK_SIZE - (line.size() - 2));
#endif
QByteArray ba = QByteArray(padding, 0x0);
ba.append(QByteArray::fromHex(QByteArray(line.toLatin1().constData() + 2)));
std::copy(ba.cbegin(), ba.cend(), m_aesIv.begin());
Expand Down
6 changes: 5 additions & 1 deletion mythtv/libs/libmythtv/captions/cc608decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,11 @@ void CC608Decoder::BufferCC(size_t mode, int len, int clr)
{
// calculate UTF-8 encoding length
tmpbuf = m_ccBuf[mode].toUtf8();
len = std::min(static_cast<int>(tmpbuf.length()), 255);
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
len = std::min(tmpbuf.length(), 255);
#else
len = std::min(tmpbuf.length(), 255LL);
#endif
}

unsigned char *bp = m_rbuf;
Expand Down
12 changes: 10 additions & 2 deletions mythtv/libs/libmythtv/eitfixup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,11 @@ void EITFixUp::FixMCA(DBEventEIT &event)
if (match.hasMatch())
{
uint matchLen = match.capturedLength(1);
uint evDescLen = std::max(static_cast<int>(event.m_description.length()), 1);
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
uint evDescLen = std::max(event.m_description.length(), 1);
#else
uint evDescLen = std::max(event.m_description.length(), 1LL);
#endif

if ((matchLen < lSUBTITLE_MAX_LEN) &&
((matchLen * 100 / evDescLen) < SUBTITLE_PCT))
Expand Down Expand Up @@ -1701,7 +1705,11 @@ void EITFixUp::FixRTL(DBEventEIT &event)
if (match.hasMatch())
{
uint matchLen = match.capturedLength(1);
uint evDescLen = std::max(static_cast<int>(event.m_description.length()), 1);
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
uint evDescLen = std::max(event.m_description.length(), 1);
#else
uint evDescLen = std::max(event.m_description.length(), 1LL);
#endif

if ((matchLen < lSUBTITLE_MAX_LEN) &&
(matchLen * 100 / evDescLen < SUBTITLE_PCT))
Expand Down
6 changes: 5 additions & 1 deletion mythtv/libs/libmythtv/recorders/HLS/HLSStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ bool HLSRecStream::SetAESIV(QString line)
// not even size, pad with front 0
line.insert(2, QLatin1String("0"));
}
int padding = std::max(0, AES_BLOCK_SIZE - (static_cast<int>(line.size()) - 2));
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
int padding = std::max(0, AES_BLOCK_SIZE - (line.size() - 2));
#else
int padding = std::max(0LL, AES_BLOCK_SIZE - (line.size() - 2));
#endif
QByteArray ba = QByteArray(padding, 0x0);
ba.append(QByteArray::fromHex(QByteArray(line.toLatin1().constData() + 2)));
m_aesIV = ba;
Expand Down
6 changes: 5 additions & 1 deletion mythtv/libs/libmythui/mythuibuttonlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,11 @@ bool MythUIButtonList::DistributeButtons(void)
* Attempt to pick a start_button which will minimize the need
* for new button allocations.
*/
start_button = std::max(static_cast<int>(m_buttonList.size()) / 2, 0);
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
start_button = std::max(m_buttonList.size() / 2, 0);
#else
start_button = std::max(m_buttonList.size() / 2, 0LL);
#endif
start_button = (start_button / std::max(m_columns, 1)) * m_columns;

if (start_button < m_itemCount / 2 &&
Expand Down
7 changes: 6 additions & 1 deletion mythtv/programs/mythbackend/recordingextender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,12 @@ void RecordingExtender::clearDownloadedInfo()
// Parse a single string. First split it into parts on a semi-colon or
// 'period space', and then selectively check those parts for the
// pattern "A vs B".
static bool parseProgramString (const QString& string, int limit,
static bool parseProgramString (const QString& string,
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
int limit,
#else
qsizetype limit,
#endif
QString& team1, QString& team2)
{
QString lString = string;
Expand Down
4 changes: 4 additions & 0 deletions mythtv/programs/mythfilerecorder/mythfilerecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ void Streamer::SendBytes(void)
int rate = (delta * m_dataRate) - m_dataRead;

read_sz = std::min(rate, read_sz);
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
read_sz = std::min((m_bufferMax - m_buffer.size()), read_sz);
#else
read_sz = std::min(static_cast<int>(m_bufferMax - m_buffer.size()), read_sz);
#endif

if (read_sz > 0)
{
Expand Down
4 changes: 4 additions & 0 deletions mythtv/programs/mythfrontend/galleryviews.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,11 @@ void DirectoryView::PopulateThumbs(ImageItem &parent, int thumbsNeeded,

// Fill parent thumbs from child files first
// Whilst they're available fill as many as possible for cache
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
for (int i = 0; i < std::min(kMaxFolderThumbnails, thumbFiles.size()); ++i)
#else
for (int i = 0; i < std::min(kMaxFolderThumbnails, static_cast<int>(thumbFiles.size())); ++i)
#endif
{
parent.m_thumbNails.append(thumbFiles.at(i)->m_thumbNails.at(0));
--thumbsNeeded;
Expand Down
6 changes: 5 additions & 1 deletion mythtv/programs/mythtv-setup/exitprompt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ void ExitPrompter::handleExit()
{
// Only report the first 4 problems
QStringList problems;
int limit = std::min(4, static_cast<int>(allproblems.size()));
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
int limit = std::min(4, allproblems.size());
#else
int limit = std::min(4LL, allproblems.size());
#endif
for (int i = 0; i < limit; ++i)
{
problems.push_back(allproblems[i]);
Expand Down
6 changes: 5 additions & 1 deletion mythtv/programs/mythutil/recordingutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ static QString CreateProgramInfoString(const ProgramInfo &pginfo)
if (!pginfo.GetSubtitle().isEmpty())
{
extra = QString(" ~ ") + pginfo.GetSubtitle();
int maxll = std::max(static_cast<int>(title.length()), 20);
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
int maxll = std::max(title.length(), 20);
#else
int maxll = std::max(title.length(), 20LL);
#endif
if (extra.length() > maxll)
extra = extra.left(maxll - 3) + "...";
}
Expand Down

0 comments on commit becf165

Please sign in to comment.