From 5d7cc1525910dbf0347d8d6849cf539c58257c9b Mon Sep 17 00:00:00 2001
From: scott snyder <snyder@bnl.gov>
Date: Thu, 13 Mar 2025 20:22:37 +0100
Subject: [PATCH] MuonCondAlg: Fix potential out-of-bounds vector access.

Because we push an element for each element in radii, so k may be larger
than the number of elements in tr_points.
Was showing up as occasional FPEs.
See ATR-30910.
---
 .../MuonCondGeneral/MuonCondAlg/src/MdtCalibDbAlg.cxx       | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondAlg/src/MdtCalibDbAlg.cxx b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondAlg/src/MdtCalibDbAlg.cxx
index 31b78599a90a..a3430cba1c4d 100644
--- a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondAlg/src/MdtCalibDbAlg.cxx
+++ b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondAlg/src/MdtCalibDbAlg.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
 */
 
 #include "MuonCondAlg/MdtCalibDbAlg.h"
@@ -487,7 +487,7 @@ StatusCode MdtCalibDbAlg::loadRt(const EventContext& ctx, MuonCalib::MdtCalibDat
             tr_point.set_error(1.0);
             if (tr_point.x2() < -99) {  // if radius is < -99 then treat time as ML Tmax difference
                 multilayer_tmax_diff = tr_point.x1();
-            } else if (k == 0 || (tr_points[k - 1].x1() < tr_point.x1() && tr_points[k - 1].x2() < tr_point.x2())) {
+            } else if (tr_points.empty() || (tr_points.back().x1() < tr_point.x1() && tr_points.back().x2() < tr_point.x2())) {
                 tr_points.push_back(tr_point);
                 ts_points.push_back(ts_point);
             }
@@ -904,4 +904,4 @@ std::unique_ptr<MuonCalib::RtResolutionLookUp> MdtCalibDbAlg::getRtResolutionInt
       }
     }
     return std::make_unique<MuonCalib::RtResolutionLookUp>(std::move(res_param));
-}
\ No newline at end of file
+}
-- 
GitLab