fix #4054 (hardcoded range check disappeared in 26dc09590b)