==11260==大小为4的写入无效
==11260==在0x402872:b2_createPair(在/home/david/Documents/programing/366终端/mainout
===11260===通过0x402BE9:b2_populateBigBucket(in/home/david/Documents/programing/366 terminal/mainout)
==11260==通过0x401993:doTads_b2(tads.c:82)
===11260===通过0x400E82:main(main.c:159)
===11260===地址0x51d0318在分配的大小为8的块之后为0字节
==11260==在0x4C28F9F:malloc(vg_replace_malloc.c:236)
==11260==by 0x402866:b2_createPair(in/home/david/Documents/programing/366 terminal/mainout)
===11260===通过0x402BE9:b2_populateBigBucket(in/home/david/Documents/programing/366 terminal/mainout)
==11260==通过0x401993:doTads_b2(tads.c:82)
===11260===通过0x400E82:main(main.c:159)
我不习惯这样——通常它也会给我前两行的行号。
此外,如果你想帮助我,我不知道为什么它不喜欢这个malloc-
pair2* b2_createPair(int nodeFrom, int nodeTo, int distance)
{
pair2* p = malloc(sizeof(pair2*));
if (p==NULL)
{
printf("Malloc was NULLn"); fflush(stdout);
}
else
{
p->distance = distance;
p->nodeFrom = nodeFrom;
p->nodeTo = nodeTo;
}
return p ;
}
(好的-只需注意p->nodeTo=nodeFrom错误-但这不会影响结果。
该结构看起来像
struct pair2_t
{
int nodeFrom;
int nodeTo;
int distance;
struct pair2_t *previous;
struct pair2_t *next;
};
typedef struct pair2_t pair2;
尝试:
pair2 *p = malloc(sizeof(pair2));
...
一定要在某个时刻free()
它。