Fix off-by-one memory error