]> granicus.if.org Git - libmatroska/commitdiff
clang-tidy: C++ casts
authorRosen Penev <rosenp@gmail.com>
Thu, 19 May 2022 01:31:55 +0000 (18:31 -0700)
committerRosen Penev <rosenp@gmail.com>
Sun, 22 May 2022 21:33:26 +0000 (14:33 -0700)
Signed-off-by: Rosen Penev <rosenp@gmail.com>
matroska/KaxTracks.h
src/KaxBlock.cpp
src/KaxBlockData.cpp
src/KaxCluster.cpp
src/KaxCues.cpp
src/KaxCuesData.cpp
src/KaxSeekHead.cpp

index cbe5db39c7e556c1b74bfffd8daa3966c20439d7..c7ef549fa50921c04a49fcc05d361a5b6e6d042b 100644 (file)
@@ -56,7 +56,7 @@ DECLARE_MKX_MASTER(KaxTrackEntry)
     */
     inline bool LacingEnabled() const {
       auto myLacing = static_cast<KaxTrackFlagLacing *>(FindFirstElt(EBML_INFO(KaxTrackFlagLacing)));
-      return((myLacing == nullptr) || (uint8(*myLacing) != 0));
+      return((myLacing == nullptr) || (static_cast<uint8>(*myLacing) != 0));
     }
 
     void SetGlobalTimecodeScale(uint64 aGlobalTimecodeScale) {
index ace92d4bd3125851c567781b2f7648cc0de09d93..7d9c65b7143af20599c9f0ee268a84ec30814b1c 100644 (file)
@@ -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<uint64>(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<int>(myBuffers.size()) - 1; i++)
-    EbmlLacingSize += CodedSizeLengthSigned(int64(myBuffers[i]->Size()) - int64(myBuffers[i - 1]->Size()), 0);
+    EbmlLacingSize += CodedSizeLengthSigned(static_cast<int64>(myBuffers[i]->Size()) - static_cast<int64>(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; i<myBuffers.size()-1; i++) {
-            SetSize_(GetSize() + myBuffers[i]->Size() + CodedSizeLengthSigned(int64(myBuffers[i]->Size()) - int64(myBuffers[i-1]->Size()), 0));
+            SetSize_(GetSize() + myBuffers[i]->Size() + CodedSizeLengthSigned(static_cast<int64>(myBuffers[i]->Size()) - static_cast<int64>(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<binary>(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; i<myBuffers.size()-1; i++) {
-            _Size = int64(myBuffers[i]->Size()) - int64(myBuffers[i-1]->Size());
+            _Size = static_cast<int64>(myBuffers[i]->Size()) - static_cast<int64>(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<int16>(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<int16>(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<LacingType>((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<int16>(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<LacingType>((*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<uint8>(_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<KaxBlockDuration *>(FindFirstElt(EBML_INFO(KaxBlockDuration), true));
-  *(static_cast<EbmlUInteger *>(&myDuration)) = TimeLength / uint64(scale);
+  *(static_cast<EbmlUInteger *>(&myDuration)) = TimeLength / static_cast<uint64>(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<uint64>(*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<const KaxInternalBlock &>(*ForwBlock).GlobalTimecode() <= timecode) &&
+          (PastBlock == nullptr || static_cast<const KaxInternalBlock &>(*PastBlock).GlobalTimecode() <= timecode))
         Block.simpleblock->SetDiscardable(false);
       else
         Block.simpleblock->SetDiscardable(true);
index de9b93fa759c7a39560efb38e960901520c4a58f..3f484d8670cc210683a6aa8c5559ceda9c8b42fc 100644 (file)
@@ -80,7 +80,7 @@ filepos_t KaxReferenceBlock::UpdateSize(bool bSaveDefault, bool bForceRender)
     assert(ParentBlock != nullptr);
 
     const KaxInternalBlock &block = *RefdBlock;
-    *static_cast<EbmlSInteger*>(this) = (int64(block.GlobalTimecode()) - int64(ParentBlock->GlobalTimecode())) / int64(ParentBlock->GlobalTimecodeScale());
+    *static_cast<EbmlSInteger*>(this) = (static_cast<int64>(block.GlobalTimecode()) - static_cast<int64>(ParentBlock->GlobalTimecode())) / static_cast<int64>(ParentBlock->GlobalTimecodeScale());
   }
   return EbmlSInteger::UpdateSize(bSaveDefault, bForceRender);
 }
index 0a7a91e5c58b9930fbdbea9e6126dcde9c432a43..d4825107fc5a52ddf5f616bd8216ffd17f002f21 100644 (file)
@@ -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<uint32>(track.TrackNumber()) != static_cast<uint32>(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; Index<Blobs.size(); Index++) {
       if (Blobs[Index]->IsSimpleBlock())
-        PushElement( (KaxSimpleBlock&) *Blobs[Index] );
+        PushElement( static_cast<KaxSimpleBlock&>(*Blobs[Index]));
       else
-        PushElement( (KaxBlockGroup&) *Blobs[Index] );
+        PushElement( static_cast<KaxBlockGroup&>(*Blobs[Index]));
     }
 
     // SilentTracks handling
@@ -198,7 +198,7 @@ filepos_t KaxCluster::Render(IOCallback & output, KaxCues & CueToUpdate, bool bS
           KaxTrackEntry & entry = *static_cast<KaxTrackEntry *>(Trk);
           auto tracknum = static_cast<uint32>(entry.TrackNumber());
           for (Index = 0; Index<Blobs.size(); Index++) {
-            if (((KaxInternalBlock&)*Blobs[Index]).TrackNum() == tracknum)
+            if (static_cast<KaxInternalBlock&>(*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<int64>(aGlobalTimecode) - static_cast<int64>(GlobalTimecode())) / static_cast<int64>(GlobalTimecodeScale());
   assert(TimecodeDelay >= int16(0x8000) && TimecodeDelay <= int16(0x7FFF));
-  return int16(TimecodeDelay);
+  return static_cast<int16>(TimecodeDelay);
 }
 
 uint64 KaxCluster::GetBlockGlobalTimecode(int16 LocalTimecode)
@@ -255,11 +255,11 @@ uint64 KaxCluster::GetBlockGlobalTimecode(int16 LocalTimecode)
   if (!bFirstFrameInside) {
     auto Timecode = static_cast<KaxClusterTimecode *>(this->FindElt(EBML_INFO(KaxClusterTimecode)));
     assert (bFirstFrameInside); // use the InitTimecode() hack for now
-    MinTimecode = MaxTimecode = PreviousTimecode = *static_cast<EbmlUInteger *>(Timecode);
+    MinTimecode = MaxTimecode = PreviousTimecode = static_cast<uint64>(*static_cast<EbmlUInteger *>(Timecode));
     bFirstFrameInside = true;
     bPreviousTimecodeIsSet = true;
   }
-  return int64(LocalTimecode * GlobalTimecodeScale()) + GlobalTimecode();
+  return static_cast<int64>(LocalTimecode * GlobalTimecodeScale()) + GlobalTimecode();
 }
 
 KaxBlockGroup & KaxCluster::GetNewBlock()
index 2fc9885076ec4110f992e2794ec3e398776b98a5..1d0d1a24c68696efd19d6481570cc7f87682a2fd 100644 (file)
@@ -125,7 +125,7 @@ const KaxCuePoint * KaxCues::GetTimecodePoint(uint64 aTimecode) const
       // check the tile
       auto aTime = static_cast<const KaxCueTime *>(tmp->FindFirstElt(EBML_INFO(KaxCueTime)));
       if (aTime != nullptr) {
-        auto _Time = uint64(*aTime);
+        auto _Time = static_cast<uint64>(*aTime);
         if (_Time > aPrevTime && _Time < TimecodeToLocate) {
           aPrevTime = _Time;
           aPointPrev = tmp;
index 7a1823140c5824915303173e35a562561312f1a4..d66d7e3661acf8420eefcea0e05830bee2c69af7 100644 (file)
@@ -198,7 +198,7 @@ bool KaxCuePoint::Timecode(uint64 & aTimecode, uint64 GlobalTimecodeScale) const
   auto aTime = static_cast<const KaxCueTime *>(FindFirstElt(EBML_INFO(KaxCueTime)));
   if (aTime == nullptr)
     return false;
-  aTimecode = uint64(*aTime) * GlobalTimecodeScale;
+  aTimecode = static_cast<uint64>(*aTime) * GlobalTimecodeScale;
   return true;
 }
 
@@ -213,8 +213,8 @@ const KaxCueTrackPositions * KaxCuePoint::GetSeekPosition() const
   auto aPoss = static_cast<const KaxCueTrackPositions *>(FindFirstElt(EBML_INFO(KaxCueTrackPositions)));
   while (aPoss != nullptr) {
     auto aPos = static_cast<const KaxCueClusterPosition *>(aPoss->FindFirstElt(EBML_INFO(KaxCueClusterPosition)));
-    if (aPos != nullptr && uint64(*aPos) < aPosition) {
-      aPosition = uint64(*aPos);
+    if (aPos != nullptr && static_cast<uint64>(*aPos) < aPosition) {
+      aPosition = static_cast<uint64>(*aPos);
       result = aPoss;
     }
 
@@ -229,7 +229,7 @@ uint64 KaxCueTrackPositions::ClusterPosition() const
   if (aPos == nullptr)
     return 0;
 
-  return uint64(*aPos);
+  return static_cast<uint64>(*aPos);
 }
 
 uint16 KaxCueTrackPositions::TrackNumber() const
@@ -238,7 +238,7 @@ uint16 KaxCueTrackPositions::TrackNumber() const
   if (aTrack == nullptr)
     return 0;
 
-  return uint16(*aTrack);
+  return static_cast<uint16>(*aTrack);
 }
 
 
index bcc2ae3f180582a5f98c3851fcc24cbab57acecc..cb82b27ad0d5a84c3f30b028686b698fb79c021f 100644 (file)
@@ -57,7 +57,7 @@ KaxSeek * KaxSeekHead::IndexThis(const EbmlElement & aElt, const KaxSegment & Pa
 
   auto & aNewID = GetChild<KaxSeekID>(aNewPoint);
   binary ID[4];
-  ((const EbmlId&)aElt).Fill(ID);
+  static_cast<const EbmlId&>(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<KaxSeek *>(*Itr);
         if (tmp->IsEbmlId(aPrev))
           return tmp;
       }
@@ -114,7 +114,7 @@ int64 KaxSeek::Location() const
   auto aPos = static_cast<KaxSeekPosition*>(FindFirstElt(EBML_INFO(KaxSeekPosition)));
   if (aPos == nullptr)
     return 0;
-  return uint64(*aPos);
+  return static_cast<uint64>(*aPos);
 }
 
 bool KaxSeek::IsEbmlId(const EbmlId & aId) const