[RFC] fix strict-overflow cases

This fixes overflows caused by (X - 1) and (X - 3) that can result into negative numbers for values that are not intended to be like this.

Effectively fixes issues #464 and #513 .
@oni-link I've updated patch according to your comments and re-based as @justinmk asked.
Change is still there. The only thing I've done is that I removed check for `s[2]`. I can't understand what github shows in this "outdated diff", but if you'll open "Files changed" you'll see how it looks now.