Reputation:
When debugging my c program I get this error message
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff77f6700 (LWP 14945)]
__strcpy_sse2_unaligned ()
at ../sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S:532
532 ../sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S: Aucun fichier ou dossier de ce type.
I think that it's "useless" to post my code because it doesn't precise the error line.
But I know I think it cames from this function:
void add_user(tlistU *lu, user * u,tuser *new)
{
tuser *nouveau = malloc(sizeof(tuser));
u =malloc(sizeof(*u));
if (lu == NULL || nouveau == NULL)
{
exit(EXIT_FAILURE);
}
strcpy(nouveau->users->nickname,u->nickname);
nouveau->next=lu->first;
lu->first=nouveau;
}
( nickname is a 9 char string )
Upvotes: 0
Views: 1411
Reputation: 63451
Your code is a little strange. The cause of the crash is probably this, however:
strcpy(nouveau->users->nickname,u->nickname);
Note that nouveau
is a block of uninitialised memory that you just requested. You are then accessing nouveau->users->nickname
, which assumes that nouveau->users
is a valid pointer.
The other thing that's happening is overwriting u
here:
u = malloc(sizeof(*u));
I suspect that what you actually meant to do was something like this:
nouveau->users = malloc(sizeof(*u));
That would solve both issues.
Upvotes: 1