Fix out-of-bounds memory access.