From: Rosen Penev Date: Thu, 19 May 2022 01:31:55 +0000 (-0700) Subject: clang-tidy: C++ casts X-Git-Tag: release-1.7.0~13^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f186237775594fea69b9ce249aaf57a86031e122;p=libmatroska clang-tidy: C++ casts Signed-off-by: Rosen Penev --- diff --git a/matroska/KaxTracks.h b/matroska/KaxTracks.h index cbe5db3..c7ef549 100644 --- a/matroska/KaxTracks.h +++ b/matroska/KaxTracks.h @@ -56,7 +56,7 @@ DECLARE_MKX_MASTER(KaxTrackEntry) */ inline bool LacingEnabled() const { auto myLacing = static_cast(FindFirstElt(EBML_INFO(KaxTrackFlagLacing))); - return((myLacing == nullptr) || (uint8(*myLacing) != 0)); + return((myLacing == nullptr) || (static_cast(*myLacing) != 0)); } void SetGlobalTimecodeScale(uint64 aGlobalTimecodeScale) { diff --git a/src/KaxBlock.cpp b/src/KaxBlock.cpp index ace92d4..7d9c65b 100644 --- a/src/KaxBlock.cpp +++ b/src/KaxBlock.cpp @@ -114,7 +114,7 @@ bool KaxInternalBlock::AddFrame(const KaxTrackEntry & track, uint64 timecode, Da if (myBuffers.empty()) { // first frame Timecode = timecode; - TrackNumber = track.TrackNumber(); + TrackNumber = static_cast(track.TrackNumber()); mInvisible = invisible; mLacing = lacing; } @@ -152,7 +152,7 @@ LacingType KaxInternalBlock::GetBestLacingType() const { } EbmlLacingSize += CodedSizeLength(myBuffers[0]->Size(), 0, IsFiniteSize()); for (i = 1; i < static_cast(myBuffers.size()) - 1; i++) - EbmlLacingSize += CodedSizeLengthSigned(int64(myBuffers[i]->Size()) - int64(myBuffers[i - 1]->Size()), 0); + EbmlLacingSize += CodedSizeLengthSigned(static_cast(myBuffers[i]->Size()) - static_cast(myBuffers[i - 1]->Size()), 0); if (SameSize) return LACING_FIXED; if (XiphLacingSize < EbmlLacingSize) @@ -191,7 +191,7 @@ filepos_t KaxInternalBlock::UpdateSize(bool /* bSaveDefault */, bool /* bForceRe case LACING_EBML: SetSize_(GetSize() + myBuffers[0]->Size() + CodedSizeLength(myBuffers[0]->Size(), 0, IsFiniteSize())); for (i=1; iSize() + CodedSizeLengthSigned(int64(myBuffers[i]->Size()) - int64(myBuffers[i-1]->Size()), 0)); + SetSize_(GetSize() + myBuffers[i]->Size() + CodedSizeLengthSigned(static_cast(myBuffers[i]->Size()) - static_cast(myBuffers[i-1]->Size()), 0)); } break; case LACING_FIXED: @@ -352,7 +352,7 @@ filepos_t KaxInternalBlock::RenderData(IOCallback & output, bool /* bForceRender SetSize_(GetSize() + 1); tmpSize -= 0xFF; } - tmpValue = binary(tmpSize); + tmpValue = static_cast(tmpSize); output.writeFully(&tmpValue, 1); SetSize_(GetSize() + 1); } @@ -377,7 +377,7 @@ filepos_t KaxInternalBlock::RenderData(IOCallback & output, bool /* bForceRender // set the size of each member in the lace for (i=1; iSize()) - int64(myBuffers[i-1]->Size()); + _Size = static_cast(myBuffers[i]->Size()) - static_cast(myBuffers[i-1]->Size()); _CodedSize = CodedSizeLengthSigned(_Size, 0); CodedValueLengthSigned(_Size, _CodedSize, _FinalHead); output.writeFully(_FinalHead, _CodedSize); @@ -432,7 +432,7 @@ uint64 KaxInternalBlock::ReadInternalHead(IOCallback & input) big_int16 b16; b16.Eval(cursor); assert(ParentCluster != nullptr); - Timecode = ParentCluster->GetBlockGlobalTimecode(int16(b16)); + Timecode = ParentCluster->GetBlockGlobalTimecode(static_cast(b16)); bLocalTimecodeUsed = false; cursor += 2; @@ -476,7 +476,7 @@ filepos_t KaxInternalBlock::ReadData(IOCallback & input, ScopeMode ReadFully) TrackNumber &= 0x7F; } - LocalTimecode = int16(Mem.GetUInt16BE()); + LocalTimecode = static_cast(Mem.GetUInt16BE()); bLocalTimecodeUsed = true; uint8 Flags = Mem.GetUInt8(); @@ -485,7 +485,7 @@ filepos_t KaxInternalBlock::ReadData(IOCallback & input, ScopeMode ReadFully) bIsDiscardable = (Flags & 0x01) != 0; } mInvisible = (Flags & 0x08) >> 3; - mLacing = LacingType((Flags & 0x06) >> 1); + mLacing = static_cast((Flags & 0x06) >> 1); // put all Frames in the list if (mLacing == LACING_NONE) { @@ -603,7 +603,7 @@ filepos_t KaxInternalBlock::ReadData(IOCallback & input, ScopeMode ReadFully) big_int16 b16; b16.Eval(cursor); - LocalTimecode = int16(b16); + LocalTimecode = static_cast(b16); bLocalTimecodeUsed = true; cursor += 2; @@ -612,7 +612,7 @@ filepos_t KaxInternalBlock::ReadData(IOCallback & input, ScopeMode ReadFully) bIsDiscardable = (*cursor & 0x01) != 0; } mInvisible = (*cursor & 0x08) >> 3; - mLacing = LacingType((*cursor++ & 0x06) >> 1); + mLacing = static_cast((*cursor++ & 0x06) >> 1); if (cursor == &_TempHead[4]) { _TempHead[0] = _TempHead[4]; } else { @@ -642,7 +642,7 @@ filepos_t KaxInternalBlock::ReadData(IOCallback & input, ScopeMode ReadFully) FrameSize = 0; do { Result += input.read(_TempHead, 1); - FrameSize += uint8(_TempHead[0]); + FrameSize += static_cast(_TempHead[0]); if (FrameSize > TotalLacedSize) throw SafeReadIOCallback::EndOfStreamX(0); LastBufferSize--; @@ -871,7 +871,7 @@ void KaxBlockGroup::SetBlockDuration(uint64 TimeLength) assert(ParentTrack != nullptr); int64 scale = ParentTrack->GlobalTimecodeScale(); KaxBlockDuration & myDuration = *static_cast(FindFirstElt(EBML_INFO(KaxBlockDuration), true)); - *(static_cast(&myDuration)) = TimeLength / uint64(scale); + *(static_cast(&myDuration)) = TimeLength / static_cast(scale); } bool KaxBlockGroup::GetBlockDuration(uint64 &TheTimecode) const @@ -882,7 +882,7 @@ bool KaxBlockGroup::GetBlockDuration(uint64 &TheTimecode) const } assert(ParentTrack != nullptr); - TheTimecode = uint64(*myDuration) * ParentTrack->GlobalTimecodeScale(); + TheTimecode = static_cast(*myDuration) * ParentTrack->GlobalTimecodeScale(); return true; } @@ -990,8 +990,8 @@ bool KaxBlockBlob::AddFrameAuto(const KaxTrackEntry & track, uint64 timecode, Da Block.simpleblock->SetDiscardable(false); } else { Block.simpleblock->SetKeyframe(false); - if ((ForwBlock == nullptr || ((const KaxInternalBlock &)*ForwBlock).GlobalTimecode() <= timecode) && - (PastBlock == nullptr || ((const KaxInternalBlock &)*PastBlock).GlobalTimecode() <= timecode)) + if ((ForwBlock == nullptr || static_cast(*ForwBlock).GlobalTimecode() <= timecode) && + (PastBlock == nullptr || static_cast(*PastBlock).GlobalTimecode() <= timecode)) Block.simpleblock->SetDiscardable(false); else Block.simpleblock->SetDiscardable(true); diff --git a/src/KaxBlockData.cpp b/src/KaxBlockData.cpp index de9b93f..3f484d8 100644 --- a/src/KaxBlockData.cpp +++ b/src/KaxBlockData.cpp @@ -80,7 +80,7 @@ filepos_t KaxReferenceBlock::UpdateSize(bool bSaveDefault, bool bForceRender) assert(ParentBlock != nullptr); const KaxInternalBlock &block = *RefdBlock; - *static_cast(this) = (int64(block.GlobalTimecode()) - int64(ParentBlock->GlobalTimecode())) / int64(ParentBlock->GlobalTimecodeScale()); + *static_cast(this) = (static_cast(block.GlobalTimecode()) - static_cast(ParentBlock->GlobalTimecode())) / static_cast(ParentBlock->GlobalTimecodeScale()); } return EbmlSInteger::UpdateSize(bSaveDefault, bForceRender); } diff --git a/src/KaxCluster.cpp b/src/KaxCluster.cpp index 0a7a91e..d482510 100644 --- a/src/KaxCluster.cpp +++ b/src/KaxCluster.cpp @@ -86,7 +86,7 @@ bool KaxCluster::AddFrameInternal(const KaxTrackEntry & track, uint64 timecode, } // force creation of a new block - if (currentNewBlock == nullptr || uint32(track.TrackNumber()) != uint32(currentNewBlock->TrackNumber()) || PastBlock != nullptr || ForwBlock != nullptr) { + if (currentNewBlock == nullptr || static_cast(track.TrackNumber()) != static_cast(currentNewBlock->TrackNumber()) || PastBlock != nullptr || ForwBlock != nullptr) { KaxBlockGroup & aNewBlock = GetNewBlock(); MyNewBlock = currentNewBlock = &aNewBlock; } @@ -184,9 +184,9 @@ filepos_t KaxCluster::Render(IOCallback & output, KaxCues & CueToUpdate, bool bS // new school, using KaxBlockBlob for (Index = 0; IndexIsSimpleBlock()) - PushElement( (KaxSimpleBlock&) *Blobs[Index] ); + PushElement( static_cast(*Blobs[Index])); else - PushElement( (KaxBlockGroup&) *Blobs[Index] ); + PushElement( static_cast(*Blobs[Index])); } // SilentTracks handling @@ -198,7 +198,7 @@ filepos_t KaxCluster::Render(IOCallback & output, KaxCues & CueToUpdate, bool bS KaxTrackEntry & entry = *static_cast(Trk); auto tracknum = static_cast(entry.TrackNumber()); for (Index = 0; Index(*Blobs[Index]).TrackNum() == tracknum) break; // this track is used } // the track wasn't found in this cluster @@ -245,9 +245,9 @@ uint64 KaxCluster::GlobalTimecode() const */ int16 KaxCluster::GetBlockLocalTimecode(uint64 aGlobalTimecode) const { - int64 TimecodeDelay = (int64(aGlobalTimecode) - int64(GlobalTimecode())) / int64(GlobalTimecodeScale()); + int64 TimecodeDelay = (static_cast(aGlobalTimecode) - static_cast(GlobalTimecode())) / static_cast(GlobalTimecodeScale()); assert(TimecodeDelay >= int16(0x8000) && TimecodeDelay <= int16(0x7FFF)); - return int16(TimecodeDelay); + return static_cast(TimecodeDelay); } uint64 KaxCluster::GetBlockGlobalTimecode(int16 LocalTimecode) @@ -255,11 +255,11 @@ uint64 KaxCluster::GetBlockGlobalTimecode(int16 LocalTimecode) if (!bFirstFrameInside) { auto Timecode = static_cast(this->FindElt(EBML_INFO(KaxClusterTimecode))); assert (bFirstFrameInside); // use the InitTimecode() hack for now - MinTimecode = MaxTimecode = PreviousTimecode = *static_cast(Timecode); + MinTimecode = MaxTimecode = PreviousTimecode = static_cast(*static_cast(Timecode)); bFirstFrameInside = true; bPreviousTimecodeIsSet = true; } - return int64(LocalTimecode * GlobalTimecodeScale()) + GlobalTimecode(); + return static_cast(LocalTimecode * GlobalTimecodeScale()) + GlobalTimecode(); } KaxBlockGroup & KaxCluster::GetNewBlock() diff --git a/src/KaxCues.cpp b/src/KaxCues.cpp index 2fc9885..1d0d1a2 100644 --- a/src/KaxCues.cpp +++ b/src/KaxCues.cpp @@ -125,7 +125,7 @@ const KaxCuePoint * KaxCues::GetTimecodePoint(uint64 aTimecode) const // check the tile auto aTime = static_cast(tmp->FindFirstElt(EBML_INFO(KaxCueTime))); if (aTime != nullptr) { - auto _Time = uint64(*aTime); + auto _Time = static_cast(*aTime); if (_Time > aPrevTime && _Time < TimecodeToLocate) { aPrevTime = _Time; aPointPrev = tmp; diff --git a/src/KaxCuesData.cpp b/src/KaxCuesData.cpp index 7a18231..d66d7e3 100644 --- a/src/KaxCuesData.cpp +++ b/src/KaxCuesData.cpp @@ -198,7 +198,7 @@ bool KaxCuePoint::Timecode(uint64 & aTimecode, uint64 GlobalTimecodeScale) const auto aTime = static_cast(FindFirstElt(EBML_INFO(KaxCueTime))); if (aTime == nullptr) return false; - aTimecode = uint64(*aTime) * GlobalTimecodeScale; + aTimecode = static_cast(*aTime) * GlobalTimecodeScale; return true; } @@ -213,8 +213,8 @@ const KaxCueTrackPositions * KaxCuePoint::GetSeekPosition() const auto aPoss = static_cast(FindFirstElt(EBML_INFO(KaxCueTrackPositions))); while (aPoss != nullptr) { auto aPos = static_cast(aPoss->FindFirstElt(EBML_INFO(KaxCueClusterPosition))); - if (aPos != nullptr && uint64(*aPos) < aPosition) { - aPosition = uint64(*aPos); + if (aPos != nullptr && static_cast(*aPos) < aPosition) { + aPosition = static_cast(*aPos); result = aPoss; } @@ -229,7 +229,7 @@ uint64 KaxCueTrackPositions::ClusterPosition() const if (aPos == nullptr) return 0; - return uint64(*aPos); + return static_cast(*aPos); } uint16 KaxCueTrackPositions::TrackNumber() const @@ -238,7 +238,7 @@ uint16 KaxCueTrackPositions::TrackNumber() const if (aTrack == nullptr) return 0; - return uint16(*aTrack); + return static_cast(*aTrack); } diff --git a/src/KaxSeekHead.cpp b/src/KaxSeekHead.cpp index bcc2ae3..cb82b27 100644 --- a/src/KaxSeekHead.cpp +++ b/src/KaxSeekHead.cpp @@ -57,7 +57,7 @@ KaxSeek * KaxSeekHead::IndexThis(const EbmlElement & aElt, const KaxSegment & Pa auto & aNewID = GetChild(aNewPoint); binary ID[4]; - ((const EbmlId&)aElt).Fill(ID); + static_cast(aElt).Fill(ID); aNewID.CopyBuffer(ID, EBML_ID_LENGTH((const EbmlId&)aElt)); return &aNewPoint; @@ -99,7 +99,7 @@ KaxSeek * KaxSeekHead::FindNextOf(const KaxSeek &aPrev) const ++Itr; for (; Itr != end(); ++Itr) { if (EbmlId(*(*Itr)) == EBML_ID(KaxSeek)) { - tmp = (KaxSeek *)(*Itr); + tmp = static_cast(*Itr); if (tmp->IsEbmlId(aPrev)) return tmp; } @@ -114,7 +114,7 @@ int64 KaxSeek::Location() const auto aPos = static_cast(FindFirstElt(EBML_INFO(KaxSeekPosition))); if (aPos == nullptr) return 0; - return uint64(*aPos); + return static_cast(*aPos); } bool KaxSeek::IsEbmlId(const EbmlId & aId) const