fix out of bounds bug (off by 1 segfault)

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