此处的代码生成以下警告: 警告C6385从“密钥”中读取无效数据:可读大小为“ _Old_2`行数”字节,但可能会读取“ 2”字节。
代码可以编译并正常运行。我已经遍历了很多遍代码,看不到next_key超出数组范围的方法。 1.将联合更改为结构没有区别。 2.奇怪的是,将形式参数重命名为'key',并注释掉本地的'key'和memcpy()时,不会生成警告。
typedef unsigned __int32 uint32_t;
typedef unsigned __int8 uint8_t;
typedef union {
uint8_t bytes[4];
uint32_t dword;
} quartet_t;
#define TABLE_SIZE 16
#define KEY_BUFFER_SIZE 16
uint8_t the_key[KEY_BUFFER_SIZE] = {0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c};
int job(uint8_t the_key[KEY_BUFFER_SIZE], uint32_t nelts);
int main()
{
job(the_key, sizeof(the_key));
}
int job(uint8_t _key[KEY_BUFFER_SIZE], uint32_t nelts)
{
int ix;
uint32_t next_key = 0;
quartet_t xlat[TABLE_SIZE];
uint8_t key[KEY_BUFFER_SIZE];
memcpy(key, _key, nelts);
for (ix = 0; ix < TABLE_SIZE; ix++)
{
if (next_key == nelts)
next_key = 0;
xlat[ix].bytes[0] = key[next_key++];
xlat[ix].bytes[1] = key[next_key++];
xlat[ix].bytes[2] = key[next_key++];
xlat[ix].bytes[3] = key[next_key++];
}
return 0;
}
输出符合预期,并且没有其他问题。我只是想了解这是我做错了还是编译器错误。