Bug 32497

Summary: sprintf printf error zero padding
Product: [Retired] Red Hat Linux Reporter: Clemens Wehrmann <cwehrmann>
Component: man-pagesAssignee: Trond Eivind Glomsrxd <teg>
Status: CLOSED CURRENTRELEASE QA Contact: Brian Brock <bbrock>
Severity: low Docs Contact:
Priority: medium    
Version: 6.2   
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2001-03-21 01:56:41 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Clemens Wehrmann 2001-03-21 01:56:37 UTC
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 17:51:17 UTC
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.