编译时通过,运行时出现了错误信息“..._CrtIsValidHeapPointer(pUserData)...”

supera2z 2005-09-15 02:35:52
编译时通过,运行时出现了错误信息
"
Debug Assertion Failed!

Program:D:\ds\\c02Debug\11.exe
File:dbgheap.c
Line:622

Expression: _CrtIsValidHeapPointer(pUserData)

For information on how your Program can cause an assertion
failure,see the Visual C++ documentation on awwerts.
.......
"


我用的是vc6,编译的程序源文件是
-------------------------
…………
typedef struct SqList{
int *elem;
int length;
int listsize;
}SqList;


int Insert(SqList &l ,int x){
int i,j;
int *newbase;

if(l.listsize<=l.length){
newbase=(int*)realloc(l.elem,(l.listsize+LISTINCREMENT)*sizeof(int));//好像是这句出了问题
if(!newbase)exit(-1);

l.elem=newbase;l.listsize+=LISTINCREMENT;

}
…………
--------------------------

请问大侠们是什么原因啊,小弟初学数据结构
...全文
635 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
supera2z 2005-09-15
  • 打赏
  • 举报
回复
是这样的,
不能realloc数组,呵呵-_-|||
大家见笑了
supera2z 2005-09-15
  • 打赏
  • 举报
回复
Expression: _CrtIsValidHeapPointer(pUserData)
---------------
问题所在,非法的堆指针

所以很可能的错误就是你下面语句中
newbase=(int*)realloc(l.elem,(l.listsize+LISTINCREMENT)*sizeof(int));
1.elem这个指针是非法的.
-------------------------
好像是这样的,我的l.elem只是指向一个数组而已……
我去试一下
xiaocai0001 2005-09-15
  • 打赏
  • 举报
回复
Expression: _CrtIsValidHeapPointer(pUserData)
---------------
问题所在,非法的堆指针

所以很可能的错误就是你下面语句中
newbase=(int*)realloc(l.elem,(l.listsize+LISTINCREMENT)*sizeof(int));
1.elem这个指针是非法的.
DentistryDoctor 2005-09-15
  • 打赏
  • 举报
回复
一般是由访问越界造成的。
xuanwenchao 2005-09-15
  • 打赏
  • 举报
回复
我觉得你的l.elem这个指针有问题?
xuanwenchao 2005-09-15
  • 打赏
  • 举报
回复
你先写成下面这样看看出不出错?
newbase=(int*)realloc(NULL,(l.listsize+LISTINCREMENT)*sizeof(int));
xiaonian_3654 2005-09-15
  • 打赏
  • 举报
回复
内存错误!
可能是由于越界引起的
xuanwenchao 2005-09-15
  • 打赏
  • 举报
回复
你传入的l 各个成员的值都正确吗,比如: l.elem=?,l.listsize=?,LISTINCREMENT=?

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧