Link to home
Start Free TrialLog in
Avatar of gus_m
gus_m

asked on

Segmentation fault after running in linux

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
Avatar of Nosfedra
Nosfedra

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?).

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.
Avatar of gus_m

ASKER

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;
}
ASKER CERTIFIED SOLUTION
Avatar of Nosfedra
Nosfedra

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of gus_m

ASKER

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