Test for negative ranges

Negative ranges would cause an infinite loop and eventually crash.