?
Solved

Segmentation fault after running in linux

Posted on 2003-03-11
6
Medium Priority
?
261 Views
Last Modified: 2010-04-15
Hi, i'm making this program in c.. when i run it under DOS.. works perfecly, and when i run it in linux i get segmentation fault.. i can't understand why.. PLEASE help.

void setParam(indice *ind,par p)
{
       /*here i get segmentation fault after this function is called from
        tag_beg_end_mode function */
     ind->params=p;
}

/* This function receive setParam function as a parameter */

int tag_beg_end_mode(FILE *aFile,int tag,indice *elem,
                    void (*f)(indice *elemento,par p))
{     etiqueta startMark,endMark;
     if (validate_open_close(aFile,&startMark,&endMark,tag))
     {   par dato;
         setPair(&dato,snd(getBegEnd(startMark)),fst(getBegEnd(endMark)));
         ( (*f)(elem,dato) );
          return 1;}
     return 0;
}

int complete_function(FILE *aFile,int tag,indice *aux)
{
return ((tag_beg_end_mode(aFile,tag++,aux,setParam));
}


No matter what i do in setParam function, whenever i use their params i get segmentation fault.
Thanx.. Gus
0
Comment
Question by:gus_m
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 3

Expert Comment

by:Nosfedra
ID: 8113008
In this case you are obviously having a null pointer derefenced there.
Try debuging it with GDB or simply print the pointer of ind parameter.

Also, watch for path names in Linux (I see a FILE structure there, is the file succesfully opened?).

0
 
LVL 2

Expert Comment

by:honey_hamster
ID: 8113089
My guess is that somehow the 'ind' pointer in setParam() is invalid.  The first thing I would do is ensure that the value of 'ind' is the same inside setParam() as 'aux' is inside complete_function().  If it is, then I'd check to see the call to complete_function() to verify that 'aux' is being set correctly in the call.  If the pointer variables have different values, then you'll need to narrow down (likely inside tag_beg_end_mode()) where the pointer variable is getting overwritten.
0
 

Author Comment

by:gus_m
ID: 8114040
the complete_function function is called from another

int process_file(char *aFileName,vecIndice *vIndices)
{
 FILE *file;
 if ((file=fopen(aFileName,"rt"))!=NULL)
  { indice aux;
    int tag=0,i=0;
    createIndex(vIndices);
    while (!reach_end(file)&&complete_function(file,tag,&aux))
       insertInIndex(vIndices,&aux);
    if (reach_end(file))
    { fclose(file);
      return 1;
    }
    fclose(file);
 }else printf("File Error");
return 0;
}
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Accepted Solution

by:
Nosfedra earned 225 total points
ID: 8114259
This is just awful to read (is this an XML parser?)... Try getting out the function calls from the function parameters and check each parameter before calling the functions. You should do this for debugging purposes and eventually get back to the original coding after sorting out the problem...

As before, the vIndices might be NULL or something. But this is like looking for a needle in the haystack, without the whole code and maybe doing some step by step walking.

Seems like the aux first passed is non initialized (is it a pointer?)

Try the gdb...
0
 
LVL 2

Expert Comment

by:honey_hamster
ID: 8114466
It has nothing to do with the problem you describe, but your 'tag' variables don't seem to do anything.  In process_file(), tag is always 0.  In complete_function, you increment tag, but since you return right away, the ++ is useless.
0
 

Author Comment

by:gus_m
ID: 8115569
I give you the points cause you were the only one who realized that it was a parser, it is very similar.
I've already done what you said, and it works perfecly in DOS but somehow it doesn't work in linux..
Thanx anyway.

Gustavo

PD: if you still want to help me, here is my e-mail. gustavo_mazzei@speedy.com.ar
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question