fix out or bounds array access. Fixes ROOT-5888.