当我在 C++ 中使用 memset 函数时如下所示
char id[LIC_KEY_INFO_MAX_LEN + 1];
/* Create random numbers */
field[LIC_KEY_RANDOM] = createRand();
/* Create identifyer */
/* Padding in 0xff */
memset(&id, 0xffffffff, LIC_KEY_INFO_MAX_LEN);
然后我用 CPP 检查我的代码,它抛出警告:
Id: memsetValueOutOfRange
Summary: The 2nd memset() argument '4294967295' doesn't fit into an 'unsigned char'.
Message: The 2nd memset() argument '4294967295' doesn't fit into an 'unsigned char'. The 2nd parameter is passed as an 'int', but the function fills the block of memory using the 'unsigned char' conversion of this value.
我的问题是什么。 非常感谢。
最佳答案
你的问题正是代码检查器告诉你的,
0xffffffff
不适合 uchar,并且 memset 的第二个参数被评估为 uchar,因此传递它 0xff
关于c++ - CPP 检查器 : memsetValueOutOfRange,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32067946/