[RFC] coverity/13749: fix negative array index read

This PR fixes one of the Coverity issues listed in #760.
This is my first contribution trying to follow the project guidelines.
Comments are most welcome.