From: Rosen Penev Date: Mon, 26 Sep 2022 22:32:19 +0000 (-0700) Subject: SonarLint: misc fixes X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ba909260b39351b309720eca5fcc869c31b34074;p=libmatroska SonarLint: misc fixes auto fixes were mostly to supress const pointer warnings Some for range loop conversions that it saw through. Signed-off-by: Rosen Penev --- diff --git a/src/KaxBlock.cpp b/src/KaxBlock.cpp index 62b0947..1aa6701 100644 --- a/src/KaxBlock.cpp +++ b/src/KaxBlock.cpp @@ -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]; diff --git a/src/KaxCluster.cpp b/src/KaxCluster.cpp index b372669..40641c9 100644 --- a/src/KaxCluster.cpp +++ b/src/KaxCluster.cpp @@ -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(*Itr)->SetParent(*this); - } else if (EbmlId(**Itr) == EBML_ID(KaxBlock)) { - static_cast(*Itr)->SetParent(*this); - } else if (EbmlId(**Itr) == EBML_ID(KaxBlockVirtual)) { - static_cast(*Itr)->SetParent(*this); + for (const auto& child : *this) { + if (EbmlId(*child) == EBML_ID(KaxBlockGroup)) { + static_cast(child)->SetParent(*this); + } else if (EbmlId(*child) == EBML_ID(KaxBlock)) { + static_cast(child)->SetParent(*this); + } else if (EbmlId(*child) == EBML_ID(KaxBlockVirtual)) { + static_cast(child)->SetParent(*this); } - ++Itr; } } diff --git a/src/KaxCues.cpp b/src/KaxCues.cpp index 7c3ce2c..fc7f91c 100644 --- a/src/KaxCues.cpp +++ b/src/KaxCues.cpp @@ -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(*Itr); + for (const auto& e : *this) { + if (EbmlId(*e) == EBML_ID(KaxCuePoint)) { + auto tmp = static_cast(e); // check the tile auto aTime = static_cast(tmp->FindFirstElt(EBML_INFO(KaxCueTime))); if (aTime != nullptr) { diff --git a/src/KaxCuesData.cpp b/src/KaxCuesData.cpp index ef36620..13cef98 100644 --- a/src/KaxCuesData.cpp +++ b/src/KaxCuesData.cpp @@ -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(NewPositions); NewRefs.AddReference(BlockReference.Reference(i).RefBlock(), GlobalTimecodeScale); } diff --git a/src/KaxSeekHead.cpp b/src/KaxSeekHead.cpp index 2b5d911..019ea37 100644 --- a/src/KaxSeekHead.cpp +++ b/src/KaxSeekHead.cpp @@ -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(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(*it); + const auto aId = static_cast(*it); const auto aEbmlId = EbmlId(aId->GetBuffer(), aId->GetSize()); if (aEbmlId == EBML_INFO_ID(Callbacks)) { return aElt; diff --git a/src/KaxSegment.cpp b/src/KaxSegment.cpp index c98c64a..ddc0915 100644 --- a/src/KaxSegment.cpp +++ b/src/KaxSegment.cpp @@ -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(*Itr)->SetParent(*this); - } - ++Itr; - } + for (const auto& child : *this) + if (EbmlId(*child) == EBML_ID(KaxCluster)) + static_cast(child)->SetParent(*this); }