Prevent exceeding array bounds in X11 key-repeat detection