From mboxrd@z Thu Jan 1 00:00:00 1970 From: hwidjaja@my-deja.com To: help-gcc@gnu.org Subject: Re: Segmentation fault Date: Wed, 17 Nov 1999 16:12:00 -0000 Message-id: <80vffq$lrp$1@nnrp1.deja.com> References: <80u79j$o86$1@nnrp1.deja.com> X-SW-Source: 1999-11/msg00266.html you have to do allocate enough memory of strbuff at insertstring() function. do malloc with new size is strlen(strbuff) + strbuff(chrstoins) hope this help. In article < 80u79j$o86$1@nnrp1.deja.com >, Sarose wrote: > OS: Redhat Linux 5.2 > GCC: gcc-2.7.2.3-14 > > Problem: > > This is my program using insertstring function > > I get Segmentation fault > > #include > #include > > char *insertstring (char *strbuf,char *chrstoins,int pos) > { > memmove ((strbuf + pos)+ strlen (chrstoins),(strbuf + pos), strlen > ((strbuf + pos))+1); > memcpy ((strbuf + pos), chrstoins, strlen (chrstoins)); > return strbuf; > } > int main() > { > char *buffer; > char *test="About Enet "; > char *test1="asdflaksdf"; > buffer = insertstring(test,test1,1); > printf("%s",buffer); > return 0; > } > > Compiling, Linking & OUTPUT > # gcc test1.c -o test > # ./test > Segmentation fault > > I do suspect 'memmove' line of insertstring functions. But HOWTO fix it > still getting puzzle?? > > Hope I will get some help for your side. > > -- > Regards, > npguy > > Sent via Deja.com http://www.deja.com/ > Before you buy. > Sent via Deja.com http://www.deja.com/ Before you buy. From mboxrd@z Thu Jan 1 00:00:00 1970 From: hwidjaja@my-deja.com To: help-gcc@gnu.org Subject: Re: Segmentation fault Date: Tue, 30 Nov 1999 23:28:00 -0000 Message-ID: <80vffq$lrp$1@nnrp1.deja.com> References: <80u79j$o86$1@nnrp1.deja.com> X-SW-Source: 1999-11n/msg00266.html Message-ID: <19991130232800.q-R4MOU6aqN5JWE5Er1SgUwciJ5XhSDnE5ngt0u_WXk@z> you have to do allocate enough memory of strbuff at insertstring() function. do malloc with new size is strlen(strbuff) + strbuff(chrstoins) hope this help. In article < 80u79j$o86$1@nnrp1.deja.com >, Sarose wrote: > OS: Redhat Linux 5.2 > GCC: gcc-2.7.2.3-14 > > Problem: > > This is my program using insertstring function > > I get Segmentation fault > > #include > #include > > char *insertstring (char *strbuf,char *chrstoins,int pos) > { > memmove ((strbuf + pos)+ strlen (chrstoins),(strbuf + pos), strlen > ((strbuf + pos))+1); > memcpy ((strbuf + pos), chrstoins, strlen (chrstoins)); > return strbuf; > } > int main() > { > char *buffer; > char *test="About Enet "; > char *test1="asdflaksdf"; > buffer = insertstring(test,test1,1); > printf("%s",buffer); > return 0; > } > > Compiling, Linking & OUTPUT > # gcc test1.c -o test > # ./test > Segmentation fault > > I do suspect 'memmove' line of insertstring functions. But HOWTO fix it > still getting puzzle?? > > Hope I will get some help for your side. > > -- > Regards, > npguy > > Sent via Deja.com http://www.deja.com/ > Before you buy. > Sent via Deja.com http://www.deja.com/ Before you buy.