Ensure item index is valid before accessing it.

Fixes #10080.

Many thanks to IRCer GreenZ for his perfect reproduction save. Load game, adv. inv., move-all -> crash.