c - Seg Fault:I can't understand why -


i pretty weird segmentation fault error when trying use same function in 2 different places.

printtvnode function work fine on main. on main:

printtvnode(headtvnode); /* works fine here */  tvnodepointer headtopic = null; topicemmissions(&headtopic,headtvnode,desiredtopic); 

when trying use printtvnode inside topicemmissions function seg fault.

void topicemmissions(tvnodepointer * headtopic,tvnodepointer headtvnode,char * desiredtopic){     tvnodepointer currenttvnode = headtvnode;     emmissionpointer currentemmission;     eventpointer currentevent;     eventpointer topicsubjects = null;     int flag,countevent = 1,countemmission = 1;      printtvnode(headtvnode); /* segmentation fault here*/     ... 

printtvnode function:

void printtvnode(tvnodepointer headtvnode){     tvnodepointer currenttvnode = headtvnode;      while ( currenttvnode != null ){         printemmission(*(currenttvnode->anemmission));          currenttvnode = currenttvnode->next;     } } 

the problem seems in following line :

printemmission(*(currenttvnode->anemmission)); 

in situation anemmission null, when try dereference it, think segfault.

make sure check anemmission not null before doing dereferencing.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -