Prevent negative lengths from wrapping around or overflowing
Refactor argument checking into a common function