if(!pc)
return;
+ pic16_unlinkpCode(pc);
+
// if((pc->type == PC_LABEL) && PCL(pc)->label)
// Safe_free(PCL(pc)->label);
fprintf(stderr,"Unlinking: ");
printpCode(stderr, pc);
#endif
- if(pc->prev)
+ if(pc->prev) {
pc->prev->next = pc->next;
- if(pc->next)
+ } else if (pc->pb && (pc->pb->pcHead == pc)) {
+ pc->pb->pcHead = pc->next;
+ }
+ if(pc->next) {
pc->next->prev = pc->prev;
+ } else if (pc->pb && (pc->pb->pcTail == pc)) {
+ pc->pb->pcTail = pc->prev;
+ }
/* move C source line down (or up) */
if (isPCI(pc) && PCI(pc)->cline) {
pBranch *pb1,*pb2;
pCode *pc1;
- if(!pc->prev || !pc->next) {
- fprintf(stderr,"unlinking bad pCode in %s:%d\n",__FILE__,__LINE__);
- exit(1);
- }
-
- /* move C source line down (or up) */
- if (isPCI(pc) && PCI(pc)->cline) {
- pc1 = pic16_findNextInstruction (pc->next);
- if (pc1 && isPCI(pc1) && !PCI(pc1)->cline) {
- PCI(pc1)->cline = PCI(pc)->cline;
- } else {
- pc1 = pic16_findPrevInstruction (pc->prev);
- if (pc1 && isPCI(pc1) && !PCI(pc1)->cline)
- PCI(pc1)->cline = PCI(pc)->cline;
- }
+ if (!pc) {
+ return;
}
- /* first remove the pCode from the chain */
- pc->prev->next = pc->next;
- pc->next->prev = pc->prev;
-
- pc->prev = pc->next = NULL;
-
- /* Now for the hard part... */
-
/* Remove the branches */
pb1 = PCI(pc)->from;
pb1 = pb1->next;
}
+ pic16_unlinkpCode (pc);
}
#endif
} // for
pc = pic16_findNextInstruction (pb->pcHead);
+ if (!pc) {
+ // empty function, avoid NULL pointer dereference
+ return;
+ } // if
todo = NULL; blacklist = NULL;
addSetHead (&todo, PCI(pc)->pcflow);