我不知道为什么我if statement
在(temp->next)->next
为 0 时不输入。我也尝试过强制转换(temp->next)->next
,(void*)
但没有成功!
void Mem_Coalesce(){
list_t* temp;
temp = freep;
if( free_node_count == 2){
if( ((char*)temp + (temp->size) ) == (char*)(temp->next)){
printf("Entered if loop\n");
temp->size += (temp->next)->size;
temp->next = NULL;
free_node_count--;
}
}
else {
printf("\n coalescing the case that free list has 3+ nodes\n");
while(temp->next != NULL ){
if( ((char*)temp + (temp->size)) == (char*)(temp->next)){
if( (temp->next)->next == NULL){
temp->size += (temp->next)->size;
temp->next = NULL; //seg fault happens here
break;
}else{
temp->size += (temp->next)->size;
temp->next = (temp->next)->next;
((temp->next)->next)->prev = temp;
}
free_node_count--;
}
temp=temp->next;
}
}
}
这是我收到的有段错误的输出:
Addr of temp->next is 7f4a836ae2e8
Addr of temp->next->next is 0
./cmd.sh: line 5: 31230 Segmentation fault (core dumped) myprogram
我是否错误地将指针值与 NULL 进行了比较?