From 440f4979d0315686b7da18f203dcecde09e66e5c Mon Sep 17 00:00:00 2001 From: Evgeny Kryshen Date: Wed, 4 Nov 2026 10:30:01 +0300 Subject: [PATCH] Cast to int64_t before multiplication --- PWGUD/TableProducer/upcCandProducerBarrel.cxx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/PWGUD/TableProducer/upcCandProducerBarrel.cxx b/PWGUD/TableProducer/upcCandProducerBarrel.cxx index 4acd05ee3a4..d9beaca9aa7 100644 --- a/PWGUD/TableProducer/upcCandProducerBarrel.cxx +++ b/PWGUD/TableProducer/upcCandProducerBarrel.cxx @@ -87,7 +87,7 @@ using SignalRef = std::pair; using DistanceMap = std::vector>; DistanceMap buildMinimumDistanceMap(std::vector const& tfIDs, - int64_t bcSOR, int32_t nBCsPerTF, + int64_t bcSOR, int64_t nBCsPerTF, std::vector& activeBCs, uint32_t maxDistance, bool skipFirstExactMatch = false) { @@ -101,8 +101,10 @@ DistanceMap buildMinimumDistanceMap(std::vector const& tfIDs, // The forward-only cursor makes the scan linear after sorting size_t nextIndex = 0; for (size_t iTF = 0; iTF < tfIDs.size(); ++iTF) { - const int64_t tfStartBC = bcSOR + tfIDs[iTF] * nBCsPerTF; - for (int64_t bcInTF = 0; bcInTF < nBCsPerTF; ++bcInTF) { // TODO why int64_t + // Cast before multiplication to prevent 32-bit integer overflow. + const int64_t tfStartBC = bcSOR + static_cast(tfIDs[iTF]) * nBCsPerTF; + // Use int64_t to keep BC arithmetic in 64 bits without additional casts. + for (int64_t bcInTF = 0; bcInTF < nBCsPerTF; ++bcInTF) { const int64_t currentBC = tfStartBC + bcInTF; while (nextIndex < activeBCs.size() && activeBCs[nextIndex] < currentBC) { ++nextIndex;