Fix some new and annoying off-by-one errors caused by our overflow checks being done way too late in the function.

I seriously spent two hours questioning basic binary logic and the compiler, even writing out detailed diagrams in GIMP, before realizing my stupid mistake.