This is the mail archive of the ecos-devel@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: strcat breaks printf


> Curtis Whitley wrote:
> > One other detail. Normally in C/C++, compiled text strings are
> > automatically null-terminated.
> > The code below contains this:  ";%d:%f:%f\0"
> > It could probably be written as: ";%d:%f:%f"
> > which would save a byte of "precious" memory!
>i
Not to mention getting rid of irritating compiler warnings...

> > This is your problem.  You are setting smsBody to point to a static
> > string and throwing away the malloc'ed memory.  What you want is
> >            strcpy(smsBody,"tcc");
> >
> >>        puts("Hello");
> >>        for (j=0;j < 1;j++)
> >>        {
> >>                tmpTime = rec->timestamp;
> >>        puts("Hello");
> >>                sprintf(tmpStr,";%d:%f:%f\0",(unsigned int) tmpTime,
> >>(float)rec->la,(float) rec->lo);
> >>                printf("tmp : %s\n",tmpStr);
> >>                strcat(smsBody,tmpStr);
> >
> > This is where you overwrite the contents of what is in memory after the
> > static "tcc" string.

Thanks this fixed the problem. 

Cheers
Wayne


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