Skip to content

Commit

Permalink
Merge pull request #15511 from bradcray/fix-sort-tuple-oob-race
Browse files Browse the repository at this point in the history
Fix race-y out-of-bounds tuple indexing error in Sort.chpl

[reviewed by @ben-albrecht]

This fixes an out-of-bounds error in tuple indexing that only happens
occasionally in practice (~1% of the time when compiling with --verify
on my Mac for test/library/packages/Sort/correctness/test-radix-bucketizer.chpl)
and as a result slipped through testing until now.  It's also subtle in that
it's done indirectly by a routine that takes the thing to be indexed into
(often an array, but this time a tuple) and its bounds as arguments, so
there was indirection involved.  Searching through the code, I'm not seeing
other obvious places that would be running afoul of the same issue.
  • Loading branch information
bradcray authored and jhoole committed Apr 13, 2020
1 parent 6fbb269 commit c1c1cc8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion modules/packages/Sort.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -1856,7 +1856,7 @@ module SequentialInPlacePartitioning {
while offsets[curbin] < endfast {
// Now go through the records in buf
// putting them in their right home.
for (idx, bin) in bucketizer.classify(buf, 1, max_buf,
for (idx, bin) in bucketizer.classify(buf, 0, max_buf-1,
criterion, startbit) {
// Swap buf[j] into its appropriate bin.
// Leave buf[j] with the next unsorted item.
Expand Down

0 comments on commit c1c1cc8

Please sign in to comment.