Bug 14190 - sprintf does not zero pad with %s
sprintf does not zero pad with %s
Status: CLOSED NOTABUG
Product: Red Hat Linux
Classification: Retired
Component: libc (Show other bugs)
6.0
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2000-07-17 17:36 EDT by steve moss
Modified: 2008-05-01 11:37 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2000-08-08 22:41:38 EDT
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 steve moss 2000-07-17 17:36:24 EDT
Building the program below shows sprintf failing to zero
pad the generated string when built on linux. It zero pads
on all other unix platforms (and winnt). The following is
the Linux man page snippet for zero padding:

   "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."

#include <stdio.h>
#include <stdlib.h>

int
main(argc, argv)
int   argc;
char  *argv[];
{
   char buff[20];
   sprintf(buff, "%012s", "4D2"); /* ZERO pad */

   printf("buff: '%s'\n", buff);
   return 0;
}
If I compile and run this code on linux 6.0 I get:

buff: '         4D2'
If I compile it on any other platform i get:

buff: '0000000004D2'
Comment 1 Cristian Gafton 2000-08-08 22:41:35 EDT
assigned to jakub
Comment 2 Jakub Jelinek 2000-08-09 09:42:44 EDT
Zero padding is only available with numerical conversions (according to Ulrich
Drepper),
and both current man pages and info libc reflect this.

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