Skip to content

Commit 7967c28

Browse files
committed
Merge branch 'briandobbins/compare_offsets_fix' (PR #631)
Fix overflow/underflow issues during qsort for the SUBSET rearranger. The comparator function given to the qsort call in the rearranger returns a 32-bit integer, but the operands can be 64-bit. Depending on the difference in value, you can get an overflow or underflow, which means you read an incorrect amount of data. * briandobbins/compare_offsets_fix: Fixes integer under/overflow issue when casting 64-bit offsets to 32-bit qsort comparator return value
2 parents f57af3a + 8b5ba2b commit 7967c28

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/clib/pio_rearrange.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1964,7 +1964,10 @@ int compare_offsets(const void *a, const void *b)
19641964
mapsort *y = (mapsort *)b;
19651965
if (!x || !y)
19661966
return 0;
1967-
return (int)(x->iomap - y->iomap);
1967+
1968+
if (x->iomap < y->iomap) { return -1; }
1969+
if (x->iomap > y->iomap) { return 1; }
1970+
return 0;
19681971
}
19691972

19701973
/**

0 commit comments

Comments
 (0)