From 7961bcfebfa2000e1473097356c3ac6aed0040bf Mon Sep 17 00:00:00 2001
From: Shaun Roe <shaun.roe@cern.ch>
Date: Thu, 14 Mar 2024 11:33:27 +0100
Subject: [PATCH] ensure vector index cannot be negative

---
 Database/IOVDbSvc/src/IOVDbFolder.cxx | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/Database/IOVDbSvc/src/IOVDbFolder.cxx b/Database/IOVDbSvc/src/IOVDbFolder.cxx
index 03f653dd46c2..56d3f96328e0 100644
--- a/Database/IOVDbSvc/src/IOVDbFolder.cxx
+++ b/Database/IOVDbSvc/src/IOVDbFolder.cxx
@@ -1331,14 +1331,17 @@ std::vector<BasicFolder> IOVDbFolder::fetchCrestObjects(cool::ValidityKey /*sinc
 	  break;
 	}
       }
-
-      iovHashVect[indIOV].first.first=iov;
-      nlohmann::json payload={};
-      payload["data"]=jsIovs[std::to_string(iov)];
-      reply=payload.dump();
+      if (indIOV>=0){
+        iovHashVect[indIOV].first.first=iov;
+        nlohmann::json payload={};
+        payload["data"]=jsIovs[std::to_string(iov)];
+        reply=payload.dump();
+      } else {
+        ATH_MSG_FATAL("indIOV is negative in IOVDbFolder::dumpFile");
+      }
     }
     catch (std::exception & e) {
-      std::string errorMessage = "Failed of parce multi iovs struct of internal iovs from payload for DCS type: " + std::string{e.what()};
+      std::string errorMessage = "Failed of parse multi iovs struct of internal iovs from payload for DCS type: " + std::string{e.what()};
       ATH_MSG_FATAL(errorMessage);
       throw std::runtime_error{errorMessage};
     }
-- 
GitLab