fix ASAN warning: `runtime error: nan is outside the range of representable values of type 'unsigned char'`