Skip to content

Commit

Permalink
Merge pull request #41572 from missirol/devel_bxvectorSafeIsEmpty
Browse files Browse the repository at this point in the history
do not allow crashes in `isEmpty(int bx)` method of `BXVector`
  • Loading branch information
cmsbuild authored May 8, 2023
2 parents e089c5a + 9e83cfc commit 03d33d0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
6 changes: 3 additions & 3 deletions DataFormats/L1Trigger/interface/BXVector.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef BXVector_h
#define BXVector_h
#ifndef DataFormats_L1Trigger_BXVector_h
#define DataFormats_L1Trigger_BXVector_h

// this class is an extension of std::vector
// designed to store objects corresponding to several time-samples (BX)
Expand Down Expand Up @@ -134,4 +134,4 @@ class BXVector {

#include "BXVector.icc"

#endif
#endif // DataFormats_L1Trigger_BXVector_h
22 changes: 18 additions & 4 deletions DataFormats/L1Trigger/interface/BXVector.icc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <cassert>

// FIXME: these 3 lines are required by other packages
#include <vector>
#include <iostream>
#include <cassert>
using namespace std;

template <class T>
Expand Down Expand Up @@ -211,15 +213,27 @@ unsigned BXVector<T>::indexFromBX(int bx) const {
// check to see if bx is empty
template <class T>
bool BXVector<T>::isEmpty(int bx) const {
if (itrs_[indexFromBX(bx)] == data_.size()) {
if (bx < bxFirst_) {
return true;
}

if (indexFromBX(bx + 1) >= itrs_.size()) {
auto const index_bx = indexFromBX(bx);

if (index_bx >= itrs_.size()) {
return true;
}

if (itrs_[index_bx] == data_.size()) {
return true;
}

auto const index_bxPlus1 = indexFromBX(bx + 1);

if (index_bxPlus1 >= itrs_.size()) {
return false;
}

if (itrs_[indexFromBX(bx)] == itrs_[indexFromBX(bx + 1)]) {
if (itrs_[index_bx] == itrs_[index_bxPlus1]) {
return true;
}

Expand Down

0 comments on commit 03d33d0

Please sign in to comment.