Bug 14190 - sprintf does not zero pad with %s
Summary: sprintf does not zero pad with %s
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: libc   
(Show other bugs)
Version: 6.0
Hardware: i386
OS: Linux
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
Depends On:
TreeView+ depends on / blocked
Reported: 2000-07-17 21:36 UTC by steve moss
Modified: 2008-05-01 15:37 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2000-08-09 02:41:38 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

Description steve moss 2000-07-17 21:36:24 UTC
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>

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-09 02:41:35 UTC
assigned to jakub

Comment 2 Jakub Jelinek 2000-08-09 13:42:44 UTC
Zero padding is only available with numerical conversions (according to Ulrich
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.