This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Segmentation fault


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 <sarose@enet.com.np> 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 <stdio.h>
> #include <string.h>
>
> 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="<a href='index.html'>About Enet </a>";
> 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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]