Fix possible out-of-bounds array access.