Fix potential array overflow