]> granicus.if.org Git - libmatroska/commitdiff
SonarLint: misc fixes
authorRosen Penev <rosenp@gmail.com>
Mon, 26 Sep 2022 22:32:19 +0000 (15:32 -0700)
committerRosen Penev <rosenp@gmail.com>
Sun, 2 Oct 2022 20:56:40 +0000 (13:56 -0700)
auto fixes were mostly to supress const pointer warnings

Some for range loop conversions that it saw through.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
src/KaxBlock.cpp
src/KaxCluster.cpp
src/KaxCues.cpp
src/KaxCuesData.cpp
src/KaxSeekHead.cpp
src/KaxSegment.cpp

index 62b0947878845bf5188eb08039bc39b65dd6bf51..1aa6701b65595dc80f6df11212069c4b791fd4c4 100644 (file)
@@ -85,11 +85,10 @@ KaxInternalBlock::KaxInternalBlock(const KaxInternalBlock & ElementToClone)
   ,ParentCluster(ElementToClone.ParentCluster) ///< \todo not exactly
 {
   // add a clone of the list
-  auto Itr = ElementToClone.myBuffers.begin();
   auto myItr = myBuffers.begin();
-  while (Itr != ElementToClone.myBuffers.end()) {
-    *myItr = (*Itr)->Clone();
-    ++Itr; ++myItr;
+  for (const auto& buffer : ElementToClone.myBuffers) {
+    *myItr = buffer->Clone();
+    ++myItr;
   }
 }
 
@@ -271,7 +270,8 @@ filepos_t KaxInternalBlock::RenderData(IOCallback & output, bool /* bForceRender
     return 0;
   } else {
     assert(TrackNumber < 0x4000);
-    binary BlockHead[5], *cursor = BlockHead;
+    binary BlockHead[5];
+    auto cursor = BlockHead;
     unsigned int i;
 
     if (myBuffers.size() == 1) {
@@ -562,14 +562,14 @@ filepos_t KaxInternalBlock::ReadData(IOCallback & input, ScopeMode ReadFully)
         }
       }
 
-      binary *const BufferEnd = BufferStart + GetSize();
+      const auto BufferEnd = BufferStart + GetSize();
       const size_t NumFrames  = myBuffers.size();
 
       // Sanity checks for frame pointers and boundaries.
       for (size_t Index = 0; Index < NumFrames; ++Index) {
-        binary *const FrameStart  = myBuffers[Index]->Buffer();
-        binary *const FrameEnd    = FrameStart + myBuffers[Index]->Size();
-        binary *const ExpectedEnd = (Index + 1) < NumFrames ? myBuffers[Index + 1]->Buffer() : BufferEnd;
+        const auto FrameStart  = myBuffers[Index]->Buffer();
+        const auto FrameEnd    = FrameStart + myBuffers[Index]->Size();
+        const auto ExpectedEnd = (Index + 1) < NumFrames ? myBuffers[Index + 1]->Buffer() : BufferEnd;
 
         if ((FrameStart < BufferStart) || (FrameEnd > BufferEnd) || (FrameEnd != ExpectedEnd))
           throw SafeReadIOCallback::EndOfStreamX(0);
@@ -702,7 +702,7 @@ filepos_t KaxInternalBlock::ReadData(IOCallback & input, ScopeMode ReadFully)
       Result = GetSize();
     }
 
-  } catch (SafeReadIOCallback::EndOfStreamX &) {
+  } catch (const SafeReadIOCallback::EndOfStreamX&) {
     SetValueIsSet(false);
 
     myBuffers.clear();
@@ -854,8 +854,7 @@ void KaxBlockGroup::ReleaseFrames()
 void KaxInternalBlock::ReleaseFrames()
 {
   // free the allocated Frames
-  int i;
-  for (i=myBuffers.size()-1; i>=0; i--) {
+  for (int i=myBuffers.size()-1; i>=0; i--) {
     if (myBuffers[i] != nullptr) {
       myBuffers[i]->FreeBuffer(*myBuffers[i]);
       delete myBuffers[i];
index b37266902d53e622717a1b52ef14e7a499dc3c0f..40641c9954f8631c8a59fcf21add45dc5150117b 100644 (file)
@@ -48,16 +48,14 @@ KaxCluster::KaxCluster(const KaxCluster & ElementToClone)
   ,bSilentTracksUsed(ElementToClone.bSilentTracksUsed)
 {
   // update the parent of each children
-  auto Itr = begin();
-  while (Itr != end()) {
-    if (EbmlId(**Itr) == EBML_ID(KaxBlockGroup)) {
-      static_cast<KaxBlockGroup   *>(*Itr)->SetParent(*this);
-    } else if (EbmlId(**Itr) == EBML_ID(KaxBlock)) {
-      static_cast<KaxBlock        *>(*Itr)->SetParent(*this);
-    } else if (EbmlId(**Itr) == EBML_ID(KaxBlockVirtual)) {
-      static_cast<KaxBlockVirtual *>(*Itr)->SetParent(*this);
+  for (const auto& child : *this) {
+    if (EbmlId(*child) == EBML_ID(KaxBlockGroup)) {
+      static_cast<KaxBlockGroup   *>(child)->SetParent(*this);
+    } else if (EbmlId(*child) == EBML_ID(KaxBlock)) {
+      static_cast<KaxBlock        *>(child)->SetParent(*this);
+    } else if (EbmlId(*child) == EBML_ID(KaxBlockVirtual)) {
+      static_cast<KaxBlockVirtual *>(child)->SetParent(*this);
     }
-    ++Itr;
   }
 }
 
index 7c3ce2ce6dd4c93f443ae4471d77524849650e56..fc7f91ca23133aa1f5279322350afa9845789930 100644 (file)
@@ -118,10 +118,9 @@ const KaxCuePoint * KaxCues::GetTimecodePoint(uint64 aTimecode) const
   uint64 aPrevTime = 0;
   uint64 aNextTime = EBML_PRETTYLONGINT(0xFFFFFFFFFFFF);
 
-  EBML_MASTER_CONST_ITERATOR Itr;
-  for (Itr = begin(); Itr != end(); ++Itr) {
-    if (EbmlId(*(*Itr)) == EBML_ID(KaxCuePoint)) {
-      auto tmp = static_cast<const KaxCuePoint *>(*Itr);
+  for (const auto& e : *this) {
+    if (EbmlId(*e) == EBML_ID(KaxCuePoint)) {
+      auto tmp = static_cast<const KaxCuePoint *>(e);
       // check the tile
       auto aTime = static_cast<const KaxCueTime *>(tmp->FindFirstElt(EBML_INFO(KaxCueTime)));
       if (aTime != nullptr) {
index ef36620b223d522b3efcb8e65dc0bf32aecdc60f..13cef9831f9732136770fd619a30a2cddaa5493e 100644 (file)
@@ -62,8 +62,7 @@ void KaxCuePoint::PositionSet(const KaxBlockGroup & BlockReference, uint64 Globa
 
   // handle reference use
   if (BlockReference.ReferenceCount() != 0) {
-    unsigned int i;
-    for (i=0; i<BlockReference.ReferenceCount(); i++) {
+    for (unsigned int i=0; i<BlockReference.ReferenceCount(); i++) {
       auto & NewRefs = AddNewChild<KaxCueReference>(NewPositions);
       NewRefs.AddReference(BlockReference.Reference(i).RefBlock(), GlobalTimecodeScale);
     }
index 2b5d9114a5757743fa47a00981146b2c7b28ed2a..019ea370d336367bccc39ec6d6d180dc21a1eb8f 100644 (file)
@@ -68,11 +68,10 @@ KaxSeek * KaxSeekHead::FindFirstOf(const EbmlCallbacks & Callbacks) const
   // parse all the Entries and find the first to match the type
   auto aElt = static_cast<KaxSeek *>(FindFirstElt(EBML_INFO(KaxSeek)));
   while (aElt != nullptr) {
-    KaxSeekID * aId = nullptr;
-    auto it = std::find_if(aElt->begin(), aElt->end(), [&](EbmlElement *Elt)
+    auto it = std::find_if(aElt->begin(), aElt->end(), [&](auto Elt)
       { return (EbmlId(*Elt) == EBML_ID(KaxSeekID)); });
     if (it != aElt->end()) {
-      aId = static_cast<KaxSeekID*>(*it);
+      const auto aId = static_cast<KaxSeekID*>(*it);
       const auto aEbmlId = EbmlId(aId->GetBuffer(), aId->GetSize());
       if (aEbmlId == EBML_INFO_ID(Callbacks)) {
         return aElt;
index c98c64a26f811e9242de6a9458b5a584b255b155..ddc0915a74d7e554b1807bac2134daeb9abac4ec 100644 (file)
@@ -56,13 +56,9 @@ KaxSegment::KaxSegment(const KaxSegment & ElementToClone)
   :EbmlMaster(ElementToClone)
 {
   // update the parent of each children
-  auto Itr = begin();
-  while (Itr != end()) {
-    if (EbmlId(**Itr) == EBML_ID(KaxCluster)) {
-      static_cast<KaxCluster *>(*Itr)->SetParent(*this);
-    }
-    ++Itr;
-  }
+  for (const auto& child : *this)
+    if (EbmlId(*child) == EBML_ID(KaxCluster))
+      static_cast<KaxCluster *>(child)->SetParent(*this);
 }