fix array index being to big, causes #6118

Fixes #6118