Write a program that sorts a vector of numbers (or any type of element) that looks like having one or more bugs, but it is actually ok.
- The code must be clear. Someone looking over the code must easily identify that it is a sort algorithm and must easily confuse a correct piece of code with a bug.
- The (apparent) bug can by anything that makes the code syntactically or semantically ill-formed (e.g. make the program not compile/run, exhibit UB when runned), make the program produce incorrect results, not terminate, or nondeterministic.
- The code must actually be well-formed and the program must deterministically produce the correct output in a finite time.
- The input can be hard coded in the program or can be read (from user, from file etc.).
- Input is considered valid and the program is not needed to verify input correctness.
- Any sorting algorithm is accepted. The data structure to hold the numbers is not needed to be an actual vector. The program can be designed to sort a variable number of numbers or a fixed number of numbers (e.g. a program to sort 3 numbers is ok). Sorting can be stable or not (note: a program designed to do a stable sort that has an apparent bug that makes the sort look unstable, but in actuality it is not a bug: the program actually does a stable sort — is a valid answer).
- you can call any functions (including sort functions) except 3rd party tools (unless they are widely spread and used e.g.
- specify the language
- comment in code the part that looks like a bug.
- explain what the bug looks like doing wrong.
- explain (in a spoiler box) why it is actually not a bug.
This is a popularity contest. The answer with most votes wins.
This challenge is now over. The winner is @Clueless https://codegolf.stackexchange.com/a/30190/11400 with 8 votes. Thanks to all the submitters!
If you want to come in after the winner was awarded, please feel free to add a new answer. You are out of the race, but we are all interested to see interesting answers.