From e6b28661d03b67fd87facfaadb7b87cb8dd80fc7 Mon Sep 17 00:00:00 2001 From: Marino Missiroli Date: Sat, 6 May 2023 15:57:39 +0200 Subject: [PATCH] do not allow crashes in isEmpty(int bx) method of BXVector --- DataFormats/L1Trigger/interface/BXVector.h | 6 +++--- DataFormats/L1Trigger/interface/BXVector.icc | 21 ++++++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/DataFormats/L1Trigger/interface/BXVector.h b/DataFormats/L1Trigger/interface/BXVector.h index 6ce09f80ba5b8..7cfa8239da265 100644 --- a/DataFormats/L1Trigger/interface/BXVector.h +++ b/DataFormats/L1Trigger/interface/BXVector.h @@ -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) @@ -134,4 +134,4 @@ class BXVector { #include "BXVector.icc" -#endif +#endif // DataFormats_L1Trigger_BXVector_h diff --git a/DataFormats/L1Trigger/interface/BXVector.icc b/DataFormats/L1Trigger/interface/BXVector.icc index 1c4efa0803d07..efee573b2f627 100644 --- a/DataFormats/L1Trigger/interface/BXVector.icc +++ b/DataFormats/L1Trigger/interface/BXVector.icc @@ -1,7 +1,4 @@ -#include -#include #include -using namespace std; template BXVector::BXVector(unsigned size, // number of objects per BX @@ -211,15 +208,27 @@ unsigned BXVector::indexFromBX(int bx) const { // check to see if bx is empty template bool BXVector::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; }