Joshua Bloch reports that Nearly All Binary Searches and Mergesorts are Broken:
The bug is in this line:6: int mid =(low + high) / 2;
In Programming Pearls Bentley says that the analogous line “sets m to the average of l and u, truncated down to the nearest integer.” On the face of it, this assertion might appear correct, but it fails for large values of the int variables low and high. Specifically, it fails if the sum of low and high is greater than the maximum positive int value (231- 1). The sum overflows to a negative value, and the value stays negative when divided by two. In C this causes an array index out of bounds with unpredictable results. In Java, it throws ArrayIndexOutOfBoundsException.
Of course, this bug does not exist in Lisp, Scheme, Python, Ruby, and other languages with proper bignum support. In the context of 21st century computer hardware, there is a strong argument that the bug is in the language, not in the line of code above.
(C# gets half marks for its checked context, where integer overflows cause an exception to be thrown.)