- 论坛徽章:
- 0
|
我的程序是完成生成一个链表:
初始化
struct RealData * p1,*p2;
p1=p2=(struct RealData *)malloc(sizeof(struct RealData));
调用链表生成函数
while (sth true)
{
p1=pin;//让p1=传进来的指针,就是原来返回的p2
//data copy
memcpy(p1->;SIM,&buf[i+8],14);
memcpy(p1->;Data,&buf[i+22],length);
p1->;len=length-18;
printf("before p1=%d\n",p1);
p2=p1;
printf("after p2=%d\n",p2);
if ((p1=(struct RealData *)malloc(sizeof(struct RealData)))==NULL)/*here*/
printf("malloc error\n" ;
p1->;next=NULL;
p2->;next=p1;
printf("after p1=%d\n",p1);
}
p2=p2->;next;
return p2;
我现在的问题是第一次调用没问题,第二次调用到here所指的那句时core down,用gdb调试,出错代码如下;
Core was generated by `./thread1'.
Program terminated with signal 11, Segmentation fault.
Cannot access memory at address 0xb7600744
#0 0xb6b04aaa in ?? ()
好像是不能new到内存,是不是?如果是会是什么原因,我的系统是redhat linux |
|