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

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

[avr-libc-dev] snprintf bug ?


From: Russell Strong
Subject: [avr-libc-dev] snprintf bug ?
Date: Thu, 13 Oct 2005 17:47:02 +1000

Hi,

I may have found a bug, I'm not sure if it would be with avr-libc or
gcc.  I'm using gcc-4.0.1, binutils-2.16.1 avr-libc-1.2.5.

The problem is with the following function and snprintf, if heading_tmp
is declared static it all works.  If it is not declared static, snprintf
puts garbage into heading_tmp ( lot of 0xb1 ).

Am I doing something illegal? Do snprintf pointers need to be static?  I
couldn't find any thing like that in the Docs.

static void update_heading_string (int hdg_reading)
{
        long delta = 0;
        unsigned char i;
        static int base_hdg = 0;
        static char heading_tmp[5];

        insert_heading (hdg_reading);

        for (i=0;i<HDG_CNT;i++)
                delta += delta_heading (headings[i], base_hdg);

        base_hdg += delta / HDG_CNT;
        if (base_hdg >= 3600)
                base_hdg -= 3600;
        else if (base_hdg < 0)
                base_hdg += 3600;

        snprintf (heading_tmp, 5, "%04X", base_hdg);

        // store heading ready for bus transmission
        cli();
        heading[0] = heading_tmp[0];
        heading[1] = heading_tmp[1];
        heading[2] = heading_tmp[2];
        heading[3] = heading_tmp[3];
        heading[4] = '\r';
        heading[5] = '\0';
        sei();
}

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


reply via email to

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