range error fix

fixes #2482

@dinhviethoa