Skip to content

Commit f95be14

Browse files
committed
Avoid unsigned promotion in parallel bin sorts
This should have worked correctly, but it makes fsanitize=integer scream, and it definitely is creepy when you think about it.
1 parent 121b633 commit f95be14

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/parallel/parallel_bin_sorter.C

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ void BinSorter<KeyType,IdxType>::binsort (const IdxType nbins,
105105

106106
// Step through the histogram until we have the
107107
// desired bin size
108-
while ((current_bin_size + histogram[current_histogram_bin] + delta) <= target_bin_size[b])
108+
while ((current_bin_size +
109+
cast_int<int>(histogram[current_histogram_bin]) +
110+
delta) <= cast_int<int>(target_bin_size[b]))
109111
{
110112
// Don't index out of the histogram!
111113
if ((current_histogram_bin+1) == phist.n_bins())
@@ -114,7 +116,7 @@ void BinSorter<KeyType,IdxType>::binsort (const IdxType nbins,
114116
current_bin_size += histogram[current_histogram_bin++];
115117
}
116118

117-
delta += current_bin_size - target_bin_size[b];
119+
delta += current_bin_size - static_cast<int>(target_bin_size[b]);
118120

119121
// Set the upper bound of the bin
120122
bin_bounds[b+1] = phist.upper_bound (current_histogram_bin);

0 commit comments

Comments
 (0)