Skip to content

Prevent integer overflow during midpoint calculation in binaryInsertionSort#9

Open
pineapplemachine wants to merge 1 commit intomziccard:masterfrom
pineapplemachine:binary-insertion-sort-overflow-fix
Open

Prevent integer overflow during midpoint calculation in binaryInsertionSort#9
pineapplemachine wants to merge 1 commit intomziccard:masterfrom
pineapplemachine:binary-insertion-sort-overflow-fix

Conversation

@pineapplemachine
Copy link
Copy Markdown

@pineapplemachine pineapplemachine commented Nov 25, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant