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: LibrarySeverity: 3 - Normal
Priority: 5 - NormalItem Group: libc code
Status: InvalidPercent Complete: 0%
Assigned to: Joerg Wunsch <joerg_wunsch>Open/Closed: Closed
Release: 1.6.7Fixed 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 File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by joerg_wunsch (Posted a comment)
  • -unavailable- added by rmann (Submitted the item)
  •  

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed 02 Feb 2011 10:15:32 AM UTCjoerg_wunschStatusNone=>Invalid
      Assigned toNone=>joerg_wunsch
      Open/ClosedOpen=>Closed

    Back to the top


    Powered by Savane 3.1-cleanup1