c - C编译器错误,或者我在这里缺少什么?
问题描述
此处的代码会生成以下警告: Warning C6385 Reading invalid data from 'key':可读大小为 '_Old_2`nelts' 字节,但可能会读取 '2' 字节。
代码编译并运行良好。我已经多次单步执行代码,并且认为 next_key 无法超出数组范围。1. 将 union 改为 struct 没有区别。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;
}
输出符合预期,没有其他问题。我只是想了解这是我做错了什么,还是编译器错误。
解决方案
推荐阅读
- c++ - 无法调整 win 32 窗口的大小
- flutter - 每当我们在 Window 10(路径)中安装 Flutter 引擎时,我如何才能找到它
- bluetooth - hciconfig 没有列出任何设备
- python - TypeError:“NoneType”对象不可调用(python 装饰器)
- http - curl:如何使用请求正文发送 HEAD 请求
- javascript - 意外类型,使用 Uint8Array 使用 tweetnacl 签署 solana 交易
- java - LibGDX 会在相机外绘制吗?
- node.js - 如何从其他开发人员运行 Node.Js 后端项目?
- flutter-plugin - 未处理的异常:MissingPluginException(在通道 plugins.flutter.io/url_launcher 上找不到方法 canLaunch 的实现)
- azure-boards - 在 Azure Boards 中,我如何使用 WIQL 列出缺少带有特定字符串前缀的标记的工作项?