为什么我会收到访问冲突运行时错误?
我有这个结构
typedef struct fpinfo
{
unsigned long chunk_offset;
unsigned long chunk_length;
unsigned char *fing_print;
}fpinfo;
typedef struct Hash_Entry {
struct Hash_Entry *next; /* Link entries within same bucket. */
unsigned namehash; /* hash value of key */
struct fpinfo fp;
} Hash_Entry;
和下面的代码行从 fing_print 数组中提取 10 msb
unsigned int h;
h = (he.fp.fing_print[0] << 2 | (he.fp.fing_print[1] & 0xC0) >> 6) & 0x3FF;
以下是我如何通过从文件
while(fscanf(rd,"%ul,%ul,%X",&test_st.fp.chunk_offset,&test_st.fp.chunk_length,&test_st.fp.fing_print) !=EOF)
{
....
}
vc 2010 中读取内容来初始化 he 数据成员,给出错误:
htable 中 0x013217f8 处出现未处理的异常。 exe: 0xC0000005: 读取位置 0xcccccccc 时发生访问冲突。
有什么问题吗?
I have this structure
typedef struct fpinfo
{
unsigned long chunk_offset;
unsigned long chunk_length;
unsigned char *fing_print;
}fpinfo;
typedef struct Hash_Entry {
struct Hash_Entry *next; /* Link entries within same bucket. */
unsigned namehash; /* hash value of key */
struct fpinfo fp;
} Hash_Entry;
and the following line of code to extract the 10 msb from the fing_print array
unsigned int h;
h = (he.fp.fing_print[0] << 2 | (he.fp.fing_print[1] & 0xC0) >> 6) & 0x3FF;
Here is how I initialized the he data member by reading contents from a file
while(fscanf(rd,"%ul,%ul,%X",&test_st.fp.chunk_offset,&test_st.fp.chunk_length,&test_st.fp.fing_print) !=EOF)
{
....
}
vc 2010 gives the error:
Unhandled exception at 0x013217f8 in htable.exe: 0xC0000005: Access violation reading location 0xcccccccc.
what is wrong with it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最可能的原因是
he.fp.fing_print
尚未初始化,因此您的进程在尝试访问其元素时崩溃。要进行验证,请打印出指针的值,或在调试器中检查它。编辑
fscanf()
代码有两个问题:%X
与一起使用&test_st.fp.fing_print
覆盖指针;test_st.fp.fing_print
分配内存。The most likely reason is that
he.fp.fing_print
has not been initialized, so your process crashes when trying to access its elements. To verify, print out the value of the pointer, or examine it in the debugger.edit There are two problems with the
fscanf()
code:%X
together with&test_st.fp.fing_print
overwrites the pointer;test_st.fp.fing_print
.可能的原因可能是 test_st 未初始化,而您正在使用它来初始化 fp。
possible reason could be that test_st is not initialized and you are using it to initialize fp.