A89: Re: Re: Re: Re: A C question


[Prev][Next][Index][Thread]

A89: Re: Re: Re: Re: A C question




> Hi!
>
> > if(ev->extra.pasteText[strlen(ev->extra.pasteText)-1] == '(')
> >   {
> >    char *string="";
> >    strcpy(string,ev->extra.pasteText);
> >    string[strlen(string)-1] = (char)0;
> >    ev->extra.pasteText = string;
> > }
>
> Huh, what you are doing!!? There is no any space allocated for your
> "string" variable: this will cause a crash!!! You need to do:
>
> char string[50];
>
> for example, instead of
>
> char *string="";

I haven't followed this, but the above code (i.e. the if(ev-> ...) stuff) looks
dangerous, since char *string is local to the if() statement. There is no
guarantee that tha data put in it will be valid after the last "}". So
ev->extra.pasteText will just point to somewhere in the stack, which will almost
certainly be used for something else later on...

 / Niklas Brunlid
Check out Prosit for the TI-89 / TI-92+ at http://prosit.ticalc.org
Random PQF Quote follows:

Still, it was a relief to get away from that macabre sight. Gander
considered that gnolls didn't look any better inside than out. He hated
their guts.
        -- (Terry Pratchett, Equal Rites)





References: