bugAVR C Runtime Library - Bugs: bug #32322, snprintf() Hex conversion field...

 
 

bug #32322: snprintf() Hex conversion field width specifiers malfunction

Submitted by:  Rick M <rmann>
Submitted on:  Tue 01 Feb 2011 11:29:26 PM UTC  
 
Category:  Library Severity:  3 - Normal
Priority:  5 - Normal Item Group:  libc code
Status:  Invalid Assigned to:  Joerg Wunsch <joerg_wunsch>
Percent Complete:  0% Open/Closed:  Closed
Release:  1.6.7 Fixed Release:  None

Add a New Comment (Rich Markup)
   

You are not logged in

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

 

Wed 02 Feb 2011 10:15:32 AM UTC, comment #1: 

No bug involved (apart from the obvious bug that you supply the
arguments for sprintf() yet try to call snprintf()),

The field width includes everything that is eventually generated by
the format specifier, so the "0x" is always included in the field
width, and already occupies the entire output field except in the 0
case.  Any actual data to be formatted thus has to overflow the output
field.

The 0 case is different, as ISO/IEC 9899:1999 requires the
implementation to not generate the 0x prefix in that case:

# The result is converted to an ``alternative form''. [...] For x (or
  X) conversion, a nonzero result has 0x (or 0X) prefixed to it. [...]

Thus, the output field is sufficient, and as the '0' flag has been
given, it is zero-padded to the left, resulting in "00".

Joerg Wunsch <joerg_wunsch>
Project AdministratorIn charge of this item.
Tue 01 Feb 2011 11:29:26 PM UTC, original submission:  

There are numerous errors around the minimum field with specifier and padding with leading zeros. The test case below is the result of using the floating-point (full) version
of the printf code.

---
#include <stdio.h>

int
main(int argc, const char** argv)
{
    char        buf[128];

   

    snprintf(buf, "%#02x", 0);          //  Writes "00"
    snprintf(buf, "%#02x", 1);          //  Writes "0x1"
    snprintf(buf, "%#02x", 0xb1);       //  Writes "0xb1"

       

    return 0;
}
---

Rick M <rmann>

 

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

Attach Files:
   
   
Comment:
   

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 (Posted a comment)
  • -email is unavailable- added by rmann (Submitted the item)
  •  

     

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2011-02-02 joerg_wunsch StatusNone => Invalid
        Assigned toNone => joerg_wunsch
        Open/ClosedOpen => Closed

    Back to the top


    Powered by Savane 3.5