fix out of bounds bug (off by 1 segfault)

Hello,

Please pick up this fix, so you do not fall victim of a runtime crash.