c - Segmentation fault and I don't know what's causing it -


main.c:132:26: warning: "/*" within comment main.c: in function ‘importsettings’: main.c:152: warning: control reaches end of non-void function main.c: in function ‘cs_init_missions’: main.c:84: warning: control reaches end of non-void function j@jonux:~/projects/csgtk/c$ ./a.out  segmentation fault j@jonux:~/projects/csgtk/c$  

this output compile -wall , running program. not ideal.

the error seems involve code below.

static xmldocptr importsettings(char file[], gtkbuilder *builder) {     cur = cur->xmlchildrennode;     while (cur != null) {         if(xmlstrequal(cur->name, (const xmlchar *) "options")) {             cur = cur->xmlchildrennode;             while (cur != null) {                 cur = cur->next;              }         }         cur = cur->next;// <- segfault here     } } 

it seems obvious outer loop attempting set cur cur->next when cur == null causing segfault. possible reconstruct loop avoid this? (i thought of do-while loop didn't pan out)

is way avoid encase statement in if statement?

i have tried fix problem. understand why failing in first place, still failing given output below:

static xmldocptr importsettings(char file[], gtkbuilder *builder){         if (file == null) {             file = "cssettings.xml";         }         //commented stuff here         settingstree = xmlparsefile(file);         //commented stuff here         cur = xmldocgetrootelement(settingstree);         cur = cur->xmlchildrennode;         while (cur != null){              if(xmlstrequal(cur->name, (const xmlchar *) "options")){                  cur = cur->xmlchildrennode;                 while (cur != null){         //commented stuff here                     if(cur->next == null)                         cur = cur->parent;                     else                         cur = cur->next;                  }             }             cur = cur->next;         } } 

is there way printf() give output near here? segmentation fault somehow stopping running before fault occurs.

first of fixed indentation little , added annotations.

static xmldocptr importsettings(char file[], gtkbuilder *builder){     cur = cur->xmlchildrennode;     while (cur != null){         if(xmlstrequal(cur->name, (const xmlchar *) "options")){             cur = cur->xmlchildrennode;             while (cur != null){                 cur = cur->next;             }             //at point, cur == null         }         cur = cur->next;//seg fault here     } } 

the problem when if statement true run second while loop leaves cur equal null.

the subsequent attempt de-reference seg fault.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -