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

Bug#510819: libc6: printf incorrectly shows argument with value 0 on conversion %#04hhx and related



On Thursday, 17 de December de 2015 18:47:58 usted escribió:
> On 2009-01-05 04:50, Noel David Torres Taño wrote:
> > Package: libc6
> > Version: 2.7-16
> > Severity: normal
> > 
> > 
> > Conversion %#04hhx in printf means "convert the argument to a uint8_t
> > (hh) and show it as an hexadecimal number (x) with leading zeros if
> > necessary (0) and a leading 0x prefix (#) in a field of total lenght
> > four (4), that is, two places for 0x and two for the argument value".
> > 
> > If the argument is 0 the expected behaviour is to show 0x00 but it shows
> > 0000
> > 
> > With other arguments it works ok.
> 
> printf has the correct behaviour as the value 0 is a special case.
> 
> Quoting POSIX [1]:
> | #
> | 
> |     Specifies that the value is to be converted to an alternative form.
> |     For o conversion, it increases the precision (if necessary) to force
> |     the first digit of the result to be zero. For x or X conversion
> |     specifiers, a non-zero result shall have 0x (or 0X) prefixed to it.
> |     For a, A, e, E, f, F, g , and G conversion specifiers, the result
> |     shall always contain a radix character, even if no digits follow the
> |
> |     radix character. Without this flag, a radix character appears in the
> |     result of these conversions only if a digit follows it. For g and G
> |
> |     conversion specifiers, trailing zeros shall not be removed from the
> |     result as they normally are. For other conversion specifiers, the
> |     behavior is undefined.
> |     0.
> 
> As you can see the '0x' prefix is added only for a non-zero value.
> That is why '0000' is the correct output here.

Then, there is a bug in the documentation of the printf function.

Please fix it there.
> 
> I am therefore closing the bug.

Please, reopen and consider as a documentation bug.

> 
> [1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/printf.html

-- 
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?

OpenPGP key: 1586 50C8 7DBF B050 DE62  EA12 70B4 00F3 EEC7 C372

Spiral galaxies always have at least TWO arms.

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


Reply to: