双向链表问题,debug 在while((tmp->pnext) !=NULL) stm32会重启
typedef struct {
uint8_t title_num;
DRAW_PARA *title;
uint8_t content_num;
DRAW_PARA *content;
}PAGE_DATA;
typedef struct page_config{
uint8_t page_n;
PAGE_DATA *temp;
char (*pdata)[40];
struct page_config *pnext;
struct page_config *pprev;
}PAGE_CONFIG;
PAGE_CONFIG* initLine(PAGE_CONFIG * head){
head=(PAGE_CONFIG*)malloc(sizeof(PAGE_CONFIG));
head->pprev=NULL;
head->pnext=NULL;
PAGE_CONFIG * list=head;
for (int i=0; i<5; i++) {
PAGE_CONFIG * body=(PAGE_CONFIG*)malloc(sizeof(PAGE_CONFIG));
body->pprev=NULL;
body->pnext=NULL;
body->temp = &page_data[i];
body->page_n = i;
body->pdata = NULL;
list->pnext=body;
body->pprev=list;
list=list->pnext;
}
return head;
}
PAGE_CONFIG* InsertTailNode(PAGE_CONFIG * head){
PAGE_CONFIG *tmp = head;
if(head == NULL)return 0;
while((tmp->pnext) !=NULL)
{
tmp = tmp->pnext;
nnn++;
}
PAGE_CONFIG *tailnode = (PAGE_CONFIG*)malloc(sizeof(PAGE_CONFIG));
if(tailnode == NULL)return 0;
tailnode->pdata = NULL;
tailnode->temp = NULL;
tailnode->page_n = nnn+1;
tmp->pnext = tailnode;
tailnode->pprev = tmp;
tailnode->pnext = NULL;
return head;
}
Head = initLine(Head);
current = Head->pnext;.
程序运行到InsertTailNode 函数内的 while((tmp->pnext) !=NULL) 就飞了, 应该是InsertTailNode 函数写的有些问题,求大神分析下