avr-libc-dev
[Top][All Lists]
Advanced

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

Re: [avr-libc-dev] Re: snprintf bug ?


From: Russell Strong
Subject: Re: [avr-libc-dev] Re: snprintf bug ?
Date: Sat, 15 Oct 2005 11:22:09 +1000

Thanks for the analysis Dmitry,  I removed the naked from main and ran
it again. It worked fine.

Thanks,
Russell

On Fri, 2005-10-14 at 14:23 +1100, Dmitry K. wrote:
> On Thursday 13 October 2005 21:46, Russell Strong wrote:
> > Hi,
> >
> > The following is the full source and Makefile for my snprintf bug
> 
> [...]
> > static void update_heading_string (int hdg_reading)
> > {
> >     long delta = 0;
> >     unsigned char i;
> >     static int base_hdg = 0;
> > //  static char heading_tmp[5];     // This works
> >     char heading_tmp[5];            // This doesn't work
> [...]
> >     snprintf (heading_tmp, 5, "%04X", base_hdg);
> [...]
> > int main () __attribute__ ((naked));
> > int main ()
> > {
> [...]
> >             update_heading_string (heading_byte_1 * 256 + heading_byte_2);
> [...]
> > OPTIMIZE       = -O2
> [...]
> 
> I have look yours program by two compilers: 3.3 and 4.0.
> Modern compiler (4.0) make function 'update_heading_string'
> as inline function (with -O2). This reduce code size (call
> is single) and speed up run.
>    You have exclude frame pointer (r28/r29) initialization
> by defining 'naked' for main.
>    But with automatic string 'heading_tmp' this is not work:
> frame pointer is used as base address.  Result is writing
> to random place.  With static string all works:
> address is absolute.
> 
> With old compiler it works also: 'update_heading_string'
> is not inlined, frame pointer is initialized in prologue
> of 'update_heading_string'.
> 
> I do not known is this bug single, I have not try to run.
> 
> Regards,
> Dmitry.
> 
> 
> 
> _______________________________________________
> AVR-libc-dev mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/avr-libc-dev

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]