From becf1650274cc52138f33e142195d9e36770a9e5 Mon Sep 17 00:00:00 2001 From: David Hampton Date: Sat, 16 Mar 2024 21:52:48 -0400 Subject: [PATCH] tidy: Remove redundant casting. (qt5/qt6) 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 --- mythtv/libs/libmythbase/mythdate.cpp | 6 +++++- mythtv/libs/libmythfreemheg/TokenGroup.cpp | 4 ++++ mythtv/libs/libmythfreemheg/TokenGroup.h | 4 ++++ mythtv/libs/libmythtv/HLS/httplivestreambuffer.cpp | 6 +++++- mythtv/libs/libmythtv/captions/cc608decoder.cpp | 6 +++++- mythtv/libs/libmythtv/eitfixup.cpp | 12 ++++++++++-- mythtv/libs/libmythtv/recorders/HLS/HLSStream.cpp | 6 +++++- mythtv/libs/libmythui/mythuibuttonlist.cpp | 6 +++++- mythtv/programs/mythbackend/recordingextender.cpp | 7 ++++++- .../programs/mythfilerecorder/mythfilerecorder.cpp | 4 ++++ mythtv/programs/mythfrontend/galleryviews.cpp | 4 ++++ mythtv/programs/mythtv-setup/exitprompt.cpp | 6 +++++- mythtv/programs/mythutil/recordingutils.cpp | 6 +++++- 13 files changed, 67 insertions(+), 10 deletions(-) diff --git a/mythtv/libs/libmythbase/mythdate.cpp b/mythtv/libs/libmythbase/mythdate.cpp index 21a307cb453..499b475789c 100644 --- a/mythtv/libs/libmythbase/mythdate.cpp +++ b/mythtv/libs/libmythbase/mythdate.cpp @@ -270,7 +270,11 @@ QString formatTime(std::chrono::milliseconds msecs, QString fmt) if (match.hasMatch()) { static constexpr std::array divisor = {1000, 100, 10, 1}; - int width = std::min(3, static_cast(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); diff --git a/mythtv/libs/libmythfreemheg/TokenGroup.cpp b/mythtv/libs/libmythfreemheg/TokenGroup.cpp index 9dbb08783db..8477c1ccb87 100644 --- a/mythtv/libs/libmythfreemheg/TokenGroup.cpp +++ b/mythtv/libs/libmythfreemheg/TokenGroup.cpp @@ -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(m_itemList.size()) - m_nFirstItem); +#endif } m_nLastCount = m_itemList.size(); diff --git a/mythtv/libs/libmythfreemheg/TokenGroup.h b/mythtv/libs/libmythfreemheg/TokenGroup.h index 095add259fd..ab056568e8c 100644 --- a/mythtv/libs/libmythfreemheg/TokenGroup.h +++ b/mythtv/libs/libmythfreemheg/TokenGroup.h @@ -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(m_itemList.size())); } +#endif protected: // MHEG Internal attributes. diff --git a/mythtv/libs/libmythtv/HLS/httplivestreambuffer.cpp b/mythtv/libs/libmythtv/HLS/httplivestreambuffer.cpp index e311a763b69..9a587eff287 100644 --- a/mythtv/libs/libmythtv/HLS/httplivestreambuffer.cpp +++ b/mythtv/libs/libmythtv/HLS/httplivestreambuffer.cpp @@ -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(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()); diff --git a/mythtv/libs/libmythtv/captions/cc608decoder.cpp b/mythtv/libs/libmythtv/captions/cc608decoder.cpp index f27b7b68ea7..61de0b4b47e 100644 --- a/mythtv/libs/libmythtv/captions/cc608decoder.cpp +++ b/mythtv/libs/libmythtv/captions/cc608decoder.cpp @@ -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(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; diff --git a/mythtv/libs/libmythtv/eitfixup.cpp b/mythtv/libs/libmythtv/eitfixup.cpp index 64c964eb39c..fee9d676f12 100644 --- a/mythtv/libs/libmythtv/eitfixup.cpp +++ b/mythtv/libs/libmythtv/eitfixup.cpp @@ -1487,7 +1487,11 @@ void EITFixUp::FixMCA(DBEventEIT &event) if (match.hasMatch()) { uint matchLen = match.capturedLength(1); - uint evDescLen = std::max(static_cast(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)) @@ -1701,7 +1705,11 @@ void EITFixUp::FixRTL(DBEventEIT &event) if (match.hasMatch()) { uint matchLen = match.capturedLength(1); - uint evDescLen = std::max(static_cast(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)) diff --git a/mythtv/libs/libmythtv/recorders/HLS/HLSStream.cpp b/mythtv/libs/libmythtv/recorders/HLS/HLSStream.cpp index c74bd50347f..59e276b4019 100644 --- a/mythtv/libs/libmythtv/recorders/HLS/HLSStream.cpp +++ b/mythtv/libs/libmythtv/recorders/HLS/HLSStream.cpp @@ -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(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; diff --git a/mythtv/libs/libmythui/mythuibuttonlist.cpp b/mythtv/libs/libmythui/mythuibuttonlist.cpp index 3138aec4e17..1d712432ddd 100644 --- a/mythtv/libs/libmythui/mythuibuttonlist.cpp +++ b/mythtv/libs/libmythui/mythuibuttonlist.cpp @@ -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(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 && diff --git a/mythtv/programs/mythbackend/recordingextender.cpp b/mythtv/programs/mythbackend/recordingextender.cpp index 89d69ce97da..7e8e3ec584a 100644 --- a/mythtv/programs/mythbackend/recordingextender.cpp +++ b/mythtv/programs/mythbackend/recordingextender.cpp @@ -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; diff --git a/mythtv/programs/mythfilerecorder/mythfilerecorder.cpp b/mythtv/programs/mythfilerecorder/mythfilerecorder.cpp index 7937d3b4248..c4e8f670aee 100644 --- a/mythtv/programs/mythfilerecorder/mythfilerecorder.cpp +++ b/mythtv/programs/mythfilerecorder/mythfilerecorder.cpp @@ -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(m_bufferMax - m_buffer.size()), read_sz); +#endif if (read_sz > 0) { diff --git a/mythtv/programs/mythfrontend/galleryviews.cpp b/mythtv/programs/mythfrontend/galleryviews.cpp index 078c9ac988c..3bb2f08e969 100644 --- a/mythtv/programs/mythfrontend/galleryviews.cpp +++ b/mythtv/programs/mythfrontend/galleryviews.cpp @@ -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(thumbFiles.size())); ++i) +#endif { parent.m_thumbNails.append(thumbFiles.at(i)->m_thumbNails.at(0)); --thumbsNeeded; diff --git a/mythtv/programs/mythtv-setup/exitprompt.cpp b/mythtv/programs/mythtv-setup/exitprompt.cpp index d4efdd7ba43..7eeb403d236 100644 --- a/mythtv/programs/mythtv-setup/exitprompt.cpp +++ b/mythtv/programs/mythtv-setup/exitprompt.cpp @@ -69,7 +69,11 @@ void ExitPrompter::handleExit() { // Only report the first 4 problems QStringList problems; - int limit = std::min(4, static_cast(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]); diff --git a/mythtv/programs/mythutil/recordingutils.cpp b/mythtv/programs/mythutil/recordingutils.cpp index 969be3f33fd..a51184eddbe 100644 --- a/mythtv/programs/mythutil/recordingutils.cpp +++ b/mythtv/programs/mythutil/recordingutils.cpp @@ -37,7 +37,11 @@ static QString CreateProgramInfoString(const ProgramInfo &pginfo) if (!pginfo.GetSubtitle().isEmpty()) { extra = QString(" ~ ") + pginfo.GetSubtitle(); - int maxll = std::max(static_cast(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) + "..."; }