Bugfix: correctly cope with end > 0xfffe.