From 2305cfecd1ddfcc07b5a41c2dc87935821bdef3e Mon Sep 17 00:00:00 2001 From: Dan Ibanez Date: Thu, 29 Mar 2018 09:01:48 -0700 Subject: [PATCH] Kokkos: fix Sort bug with empty bins See #2471 and kokkos/kokkos#1503 Out-of-bounds access when sorting an empty bin. --- packages/kokkos/algorithms/src/Kokkos_Sort.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/kokkos/algorithms/src/Kokkos_Sort.hpp b/packages/kokkos/algorithms/src/Kokkos_Sort.hpp index 888476045b8e..21e9ec64bbdc 100644 --- a/packages/kokkos/algorithms/src/Kokkos_Sort.hpp +++ b/packages/kokkos/algorithms/src/Kokkos_Sort.hpp @@ -362,8 +362,10 @@ class BinSort { KOKKOS_INLINE_FUNCTION void operator() (const bin_sort_bins_tag& tag, const int&i ) const { + auto bin_size = bin_count_const(i); + if (bin_size <= 1) return; + int upper_bound = bin_offsets(i)+bin_size; bool sorted = false; - int upper_bound = bin_offsets(i)+bin_count_const(i); while(!sorted) { sorted = true; int old_idx = sort_order(bin_offsets(i));