fix integer overflow preventing bounds check (Shane Huntley)