bugAVR C Runtime Library - Bugs: bug #43442, sprintf function incorrectly...


bug #43442: sprintf function incorrectly interprets format parameters

Submitted by:  None
Submitted on:  Sun 19 Oct 2014 10:00:12 PM UTC  
Category:  Library Severity:  3 - Normal
Priority:  5 - Normal Item Group:  libc code
Status:  Invalid Assigned to:  None
Percent Complete:  0% Originator Email:  -email is unavailable-
Open/Closed:  Closed Release:  1.8.0
Fixed Release:  None

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Sun 19 Oct 2014 10:54:34 PM UTC, comment #1: 

Problem solved - it was caused by variables that were in BCD format.

Sun 19 Oct 2014 10:00:12 PM UTC, original submission:  

Function sprintf incorrectly interprets passed parameters, on following example:

char someString[3];
uint8_t number = 0;

number = 9;
sprintf(someString, "%02u", number);

Now in someString we will have 09 but when we do this:

number = 10;
sprintf(someString, "%02u", number);

Then in someString we have 16, not 10 as we expect. But when we change format from "%02u" to "%02x" then it works fine, and we have 10 in someString. Of course with values 20, 30 and so on problem also exist. From what I can see, this function interpret %u as hex(10 in HEX is 16 in DEC) and %x as decimal but it should be interpreted inversely.



(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by joerg_wunsch (Updated the item)
  • -email is unavailable- added by None (Submitted the item)



    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-10-20 joerg_wunsch StatusNone => Invalid
        Open/ClosedOpen => Closed

    Back to the top

    Powered by Savane 3.5