strcpy(stc->val,var) = Segmention Fault

Marcel Cox marcel_cox@hotmail.com
Mon Jul 21 10:52:00 GMT 2003


You have a couple of these in your code:

stc->val=(char *) malloc(strlen(var));

strcpy(stc->val,var);

This is wrong. You are not allocating space for the terminating null
character and you are always overwriting the end of your allocated memory
zones. This just happens to work by chance on your other compiler, but it is
definitely not a surprise that it can give a segmentation fault.
-- 
Marcel Cox

"Uílton O. Dutra" <uilton@schmitt.com.br> wrote in message
news:200307181640030460.0015EFFB@mail.schmitt.com.br...
Hi folks,

I create simple program to read configurations files.
With Bcc32-Win98 my prog works fine, but on Gcc-Linux I got "Segmention
Fault" in "strcpy(stc->val,var)".
What's wrong?

Thanks,

UOD





More information about the Gcc mailing list