Fix accessing an negative array index.

The problem was introduced in 365714aeabd42106da91842d42ba53be399791ab.
Fendrin please review the fix.