Spot the bug… previous: Your services will not be needed, thank you next: World’s Smallest No SQL database Do you see it? It took me ages to find it. Comments 07/02/2013 09:09 AM by Igal Tabachnik Yay scoping braces! 07/02/2013 09:10 AM by Fredrik Ha ha, it's quite subtle, but so obvious once you spot it. 07/02/2013 09:11 AM by Sebastian I think there is something 'else' missing ;-) 07/02/2013 09:15 AM by Ramon Smits Missing else? 07/02/2013 09:26 AM by Sam LOL, I didn't saw it either 07/02/2013 09:46 AM by Marc Brooks Not to mention the sheer lunacy of mid not being related to target in any discernable way. Ugh. (oh, yeah, and missing else) 07/02/2013 10:00 AM by P.Czatrowski Apart from missing else, what about arithmetic overflow? I would change the line: var mid = (left + right + 1) / 2; to this: var mid = left + (right - left + 1) / 2; You still get the same result, but it's a little bit safer for higher values. 07/02/2013 10:08 AM by tobi The bug aside, I'd use checked((left + right + 1) / 2). 07/03/2013 08:25 AM by Roman Boiko Another potential problem: behavior of comparator might be not aligned with subtraction, so that _comparator.Compare(mid-1, mid) >=0 07/05/2013 07:48 AM by Alex This is really a tricky problem to spot. :) Everyone is focused on the code inside the brackets and the missing "else" is not being observed very fast. 07/12/2013 09:18 AM by Adam Fridental Sorry to dissapoint, took me a second. Anyway, I don't belive in scoping braces when they contain 1 line, it's not safer and not easier to read.. just redundant. Comments have been closed on this topic.