fix potential array boundary error