Protect quicksort pivot index from overflow.
authorW. Trevor King <wking@drexel.edu>
Mon, 25 Oct 2010 15:55:31 +0000 (11:55 -0400)
committerW. Trevor King <wking@drexel.edu>
Mon, 25 Oct 2010 15:55:31 +0000 (11:55 -0400)
commitace460cb1c24d1dc9a5b0156cefbc6bce235b73d
tree26d6637a64ebcc3138bd84da9df64e2df209cc38
parent8b699b45fb025be6e1673a40f9f00277105faffb
Protect quicksort pivot index from overflow.

Mentioned on
  http://en.wikipedia.org/wiki/Quicksort

  Note the left + (right-left)/2 expression. (left + right)/2 would
  seem to be adequate, but in the presence of overflow, can give the
  wrong answer; for example, in signed 16-bit arithmetic, 32000 +
  32000 is not 64000 but -1536, and dividing that number by two will
  give you a new pivotIndex of -768 — obviously wrong.
src/sorting/quicksort.c