I have a segmentation fault in this program
Code:
struct obj {
wchar_t *name;
struct obj *father;
};
struct pbl {
wchar_t *name;
struct obj *obj;
struct pbl *next;
};
struct pbt {
wchar_t *name, *path;
struct pbl *first;
};
int newTarget(struct pbt** t ){
int
ret = -1;
*t = malloc( (size_t) sizeof(struct pbt)); // <<<< HERE
if (!(*t))
goto endl;
ret = 0;
endl:
return ret;
}
int main(int argc, char** arg){
int
ret = -1;
struct pborca_pbt
**target = NULL;
if ( newTarget(target) )
goto endl;
ret = 0;
endl:
return ret;
}
Probably it's because I'm assigning the memory from malloc to *t, and t is NULL.
But how can I malloc a structure passed by reference then?
I guess I'm missing the point.
EDIT:
Yeah, ofc, I've found the answer.
target is getting passed by copy.
What i need is
Code:
struct pborca_pbt *target;
if ( newTarget( &target) ) goto endl;