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

Bug#510819: marked as done (libc6: printf incorrectly shows argument with value 0 on conversion %#04hhx and related)



Your message dated Thu, 17 Dec 2015 19:47:58 +0100
with message-id <20151217184758.GA20284@aurel32.net>
and subject line Re: Bug#510819: libc6: printf incorrectly shows argument with value 0 on conversion %#04hhx and related
has caused the Debian Bug report #510819,
regarding libc6: printf incorrectly shows argument with value 0 on conversion %#04hhx and related
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact owner@bugs.debian.org
immediately.)


-- 
510819: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=510819
Debian Bug Tracking System
Contact owner@bugs.debian.org with problems
--- Begin Message ---
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.

-- System Information:
Debian Release: 5.0
  APT prefers testing
  APT policy: (990, 'testing'), (500, 'testing-proposed-updates'), (500, 'proposed-updates'), (500, 'unstable'), (500, 'stable'), (1, 'experimental')
Architecture: i386 (i686)

Kernel: Linux 2.6.26-1-686 (SMP w/2 CPU cores)
Locale: LANG=es_ES.UTF-8, LC_CTYPE=es_ES.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages libc6 depends on:
ii  libgcc1                       1:4.3.2-1  GCC support library

libc6 recommends no packages.

Versions of packages libc6 suggests:
ii  glibc-doc                     2.7-16     GNU C Library: Documentation
ii  libc6-i686                    2.7-16     GNU C Library: Shared libraries [i
ii  locales                       2.7-16     GNU C Library: National Language (

-- debconf information:
  glibc/upgrade: true
  glibc/restart-failed:
  glibc/restart-services:



--- End Message ---
--- Begin Message ---
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.

I am therefore closing the bug.

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

-- 
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
aurelien@aurel32.net                 http://www.aurel32.net

--- End Message ---

Reply to: