node-timsort icon indicating copy to clipboard operation
node-timsort copied to clipboard

Prevent integer overflow during midpoint calculation in `binaryInsertionSort`

Open pineapplemachine opened this issue 9 years ago • 0 comments

Changed line 211 from

let mid = (left + right) >>> 1;

to

let mid = left + ((right - left) >>> 1);

because the previous implementation would yield incorrect results for large values of left and/or right.

This is the way the operation is done, for example, in gallopLeft on line 315

pineapplemachine avatar Nov 25 '16 13:11 pineapplemachine