Bug 32497 - sprintf printf error zero padding
sprintf printf error zero padding
Status: CLOSED CURRENTRELEASE
Product: Red Hat Linux
Classification: Retired
Component: man-pages (Show other bugs)
6.2
i386 Linux
medium Severity low
: ---
: ---
Assigned To: Trond Eivind Glomsrxd
Brian Brock
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2001-03-20 20:56 EST by Clemens Wehrmann
Modified: 2007-04-18 12:32 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2001-03-20 20:56:41 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Clemens Wehrmann 2001-03-20 20:56:37 EST
From Bugzilla Helper:
User-Agent: Mozilla/4.76 [en] (X11; U; Linux 2.2.18 i686)


[s]printf man page claims '0' flag pads with zeros for (almost) all
conversions.  In fact it only does so for numeric conversions.

I quote from "man sprintf":

                  0      specifying  zero  padding.   For all conver-
                         sions  except  n,  the  converted  value  is
                         padded  on  the  left with zeros rather than
                         blanks.  If a  precision  is  given  with  a
                         numeric  conversion  (d,  i, o, u, i, x, and
                         X), the 0 flag is ignored.

Basically, neither "c" nor "s" obey the "pad with zeros" flag, nor,
 according to most people, should they, but the man page implies that
 they should.

Reproducible: Always
Steps to Reproduce:
$ more junk.c 
#include <stdio.h>

int main()
{
  printf("%06c\n", 'A');
  return (0);
}

Actual Results:  $ make junk
cc     junk.c   -o junk
$ ./junk
     A

Expected Results:  Man page suggests (in error) that this should have
returned
$ ./junk
00000A
Comment 1 Trond Eivind Glomsrxd 2001-03-21 12:51:17 EST
A newer man page (from Red Hat Linux 7) tells:

   0      The value should be zero padded.  For d, i,  o,  u,
              x,  X,  a, A, e, E, f, F, g, and G conversions, the
              converted value is padded on the  left  with  zeros
              rather  than  blanks.   If  the  0 and - flags both
              appear, the 0 flag is ignored.  If a  precision  is
              given with a numeric conversion (d, i, o, u, x, and
              X), the 0 flag is ignored.  For other  conversions,
              the behavior is undefined.


Note You need to log in before you can comment on or make changes to this bug.