From 6821fd30dce195c4c7178e97485134d6b861ecec Mon Sep 17 00:00:00 2001 From: Christian Pulvermacher Date: Mon, 23 Feb 2015 14:19:10 +0100 Subject: [PATCH] Reuse range-specific AbsorbObjects() code Also adds a check to ensure the upper index is inside array bounds. Fixes https://sft.its.cern.ch/jira/browse/ROOT-6995 --- core/cont/src/TClonesArray.cxx | 35 ++++++---------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/core/cont/src/TClonesArray.cxx b/core/cont/src/TClonesArray.cxx index 4dc752d833577..bbb56e6dbec29 100644 --- a/core/cont/src/TClonesArray.cxx +++ b/core/cont/src/TClonesArray.cxx @@ -990,34 +990,7 @@ void TClonesArray::AbsorbObjects(TClonesArray *tc) // tests if (tc == 0 || tc == this || tc->GetEntriesFast() == 0) return; - if (fClass != tc->fClass) { - Error("AbsorbObjects", "cannot absorb objects when classes are different"); - return; - } - - // cache the sorted status - Bool_t wasSorted = IsSorted() && tc->IsSorted() && - (Last() == 0 || Last()->Compare(tc->First()) == -1); - - // expand this - Int_t oldSize = GetEntriesFast(); - Int_t newSize = oldSize + tc->GetEntriesFast(); - if(newSize > fSize) - Expand(newSize); - - // move - for (Int_t i = 0; i < tc->GetEntriesFast(); ++i) { - fCont[oldSize+i] = tc->fCont[i]; - (*fKeep)[oldSize+i] = (*(tc->fKeep))[i]; - tc->fCont[i] = 0; - (*(tc->fKeep))[i] = 0; - } - - // cleanup - fLast = newSize-1; - tc->fLast = -1; - if (!wasSorted) - Changed(); + AbsorbObjects(tc, 0, tc->GetEntriesFast() - 1); } //______________________________________________________________________________ @@ -1026,7 +999,7 @@ void TClonesArray::AbsorbObjects(TClonesArray *tc, Int_t idx1, Int_t idx2) // Directly move the range of object pointers from tc without cloning // (copying). // This TClonesArray takes over ownership of all of tc's object pointers - // from idx1 to idx2. The tc array is re-arranged by return. + // from idx1 to idx2 (inclusive). The tc array is re-arranged by return. // tests if (tc == 0 || tc == this || tc->GetEntriesFast() == 0) return; @@ -1039,6 +1012,10 @@ void TClonesArray::AbsorbObjects(TClonesArray *tc, Int_t idx1, Int_t idx2) Error("AbsorbObjects", "range is not valid: idx1>idx2"); return; } + if (idx2 >= tc->GetEntriesFast()) { + Error("AbsorbObjects", "range is not valid: idx2 out of bounds"); + return; + } // cache the sorted status Bool_t wasSorted = IsSorted() && tc->IsSorted() &&