On Sat, 2015-08-29 at 08:54 +0200, Dan Richard wrote:
> My Debian is with kernel 4.0.0-2-rt-686-pae, and gcc (Debian 4.9.2
> -10) 4.9.2.
>
> I have a program where it uses strcpy, but when executing
> (compilation successfully), it throws segment fault. Debugging with
> gdb, it shows that it goes worng in strcpy function.
>
> _strcpy_sse2 () at ../sysdeps/i386/i686/multiarch/strcpy-sse2.S:2099
> 2099 ../sysdeps/i386/i686/multiarch/strcpy-sse2.S: No such file or
> directory.
>
> I wrote a simple program, it also throws segment fault.
>
> #include <string.h>
> #include <stdio.h>
> int main(int argc, char **argv)
> {
> char *str;
> strcpy(str, "hello");
> printf("say %s\n", str);
> return 0;
> }
>
> How can I fix this problem?
>
> Thanks
>
Hi,
You are failing to allocate memory. This sample program should look
something like this:
#include <string.h>
#include <stdio.h>
#include <malloc.h>
int main(int argc, char **argv)
{
char *str;
str = malloc (5);
strcpy(str, "hello");
printf("say %s\n", str);
free(str);
return 0;
}
Best,
Lev
Attachment:
signature.asc
Description: This is a digitally signed message part