Skip to content

Commit 6db87c3

Browse files
authored
[PWGUD] Cast to int64_t before multiplication (#18579)
1 parent 2e5cb24 commit 6db87c3

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎PWGUD/TableProducer/upcCandProducerBarrel.cxx‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ using SignalRef = std::pair<int32_t, int16_t>;
8787
using DistanceMap = std::vector<std::vector<uint32_t>>;
8888

8989
DistanceMap buildMinimumDistanceMap(std::vector<uint32_t> const& tfIDs,
90-
int64_t bcSOR, int32_t nBCsPerTF,
90+
int64_t bcSOR, int64_t nBCsPerTF,
9191
std::vector<int64_t>& activeBCs, uint32_t maxDistance,
9292
bool skipFirstExactMatch = false)
9393
{
@@ -101,8 +101,10 @@ DistanceMap buildMinimumDistanceMap(std::vector<uint32_t> const& tfIDs,
101101
// The forward-only cursor makes the scan linear after sorting
102102
size_t nextIndex = 0;
103103
for (size_t iTF = 0; iTF < tfIDs.size(); ++iTF) {
104-
const int64_t tfStartBC = bcSOR + tfIDs[iTF] * nBCsPerTF;
105-
for (int64_t bcInTF = 0; bcInTF < nBCsPerTF; ++bcInTF) { // TODO why int64_t
104+
// Cast before multiplication to prevent 32-bit integer overflow.
105+
const int64_t tfStartBC = bcSOR + static_cast<int64_t>(tfIDs[iTF]) * nBCsPerTF;
106+
// Use int64_t to keep BC arithmetic in 64 bits without additional casts.
107+
for (int64_t bcInTF = 0; bcInTF < nBCsPerTF; ++bcInTF) {
106108
const int64_t currentBC = tfStartBC + bcInTF;
107109
while (nextIndex < activeBCs.size() && activeBCs[nextIndex] < currentBC) {
108110
++nextIndex;

0 commit comments

Comments
 (0)