FUTURE POSTS
- Partial writes, IO_Uring and safety - about one day from now
- Configuration values & Escape hatches - 4 days from now
- What happens when a sparse file allocation fails? - 6 days from now
- NTFS has an emergency stash of disk space - 8 days from now
- Challenge: Giving file system developer ulcer - 11 days from now
And 4 more posts are pending...
There are posts all the way to Feb 17, 2025
Comments
Yay scoping braces!
Ha ha, it's quite subtle, but so obvious once you spot it.
I think there is something 'else' missing ;-)
Missing else?
LOL, I didn't saw it either
Not to mention the sheer lunacy of mid not being related to target in any discernable way. Ugh.
(oh, yeah, and missing else)
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.
The bug aside, I'd use checked((left + right + 1) / 2).
Another potential problem: behavior of comparator might be not aligned with subtraction, so that
_comparator.Compare(mid-1, mid) >=0
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.
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.
Comment preview