Fixes a regression in 91f9f1a890, which added the range check into the wrong if statement.
91f9f1a890