Check index bounds.