fix a bug that index out of range
Merge pull request #3806 from minggo/master

[ci skip]fix a bug that index may out of range