From kato@eclogite.eps.nagoya-u.ac.jp  Wed Nov  1 18:57:09 1995
Received: from marble.eps.nagoya-u.ac.jp (marble.eps.nagoya-u.ac.jp [133.6.57.68])
          by freefall.freebsd.org (8.6.12/8.6.6) with ESMTP id SAA08327
          for <FreeBSD-gnats-submit@freebsd.org>; Wed, 1 Nov 1995 18:57:08 -0800
Received: (from kato@localhost) by marble.eps.nagoya-u.ac.jp (8.6.12+2.4W/3.3W9) id LAA00678; Thu, 2 Nov 1995 11:57:06 +0900
Message-Id: <199511020257.LAA00678@marble.eps.nagoya-u.ac.jp>
Date: Thu, 2 Nov 1995 11:57:06 +0900
From: kato@eclogite.eps.nagoya-u.ac.jp
Reply-To: kato@eclogite.eps.nagoya-u.ac.jp
To: FreeBSD-gnats-submit@freebsd.org
Subject: printf goroup bug [`.' optional precision]
X-Send-Pr-Version: 3.2

>Number:         809
>Category:       bin
>Synopsis:       `.' gives the minimum number of (DIGITS+SIGN)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bde
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Nov  1 19:00:01 PST 1995
>Closed-Date:    Wed Mar 20 10:29:03 PST 1996
>Last-Modified:  Wed Mar 20 10:29:49 PST 1996
>Originator:     KATO Takenori
>Release:        FreeBSD 2.2-CURRENT i386
>Organization:
Dept. Earth Planet. Sci. Nagoya Univ.  Nagoya 464-01, JAPAN
>Environment:

All FreeBSD 2.X box

>Description:

The C library functions, printf group may violate ANSI standard.

The optional precision `.' gives the minimun number of not digits but
DIGITS+SIGN.  That is, vfprintf routine assumes digit = [0-9] & [+-].

I think `digit' should not include sign flag.

This may be a 4.4BSD-derived bug, because other *BSD box shows same
synopsis (not including NetBSD 1.1).

This affect many of programs, which assume digit consists of [0-9].
One of the examples is libI77.

>How-To-Repeat:

The C code,

#include <stdio.h>

void main(void)
{
    printf("%.2d\n", 1);
	printf("%+.2d\n", 1);
	printf("%+.3d\n", 1);
}

gives following result:

01
+1
+01

On the contrary, NEWS, Sun, OSF/1 and Borland C++ 3.1 give following:

01
+01
+001

>Fix:

not known.  (maybe bug stays in /usr/src/lib/libc/stdio/vfprintf.c?)

>Release-Note:
>Audit-Trail:

From: Bruce Evans <bde@zeta.org.au>
To: FreeBSD-gnats-submit@freebsd.org, kato@eclogite.eps.nagoya-u.ac.jp
Cc:  Subject: Re: bin/809: printf goroup bug [`.' optional precision]
Date: Fri, 3 Nov 1995 20:02:56 +1100

 >#include <stdio.h>
 
 >void main(void)
 >{
 >    printf("%.2d\n", 1);
 >	printf("%+.2d\n", 1);
 >	printf("%+.3d\n", 1);
 >}
 
 >gives following result:
 
 >01
 >+1
 >+01
 
 Signs and other prefixes reduce the precision in all cases that I looked at:
 
 	printf("%.3d\n", -1);
 	printf("%.3d\n", 1);
 	printf("%+.3d\n", -1);
 	printf("%+.3d\n", 1);
 	printf("% .3d\n", -1);
 	printf("% .3d\n", 1);
 	printf("%#.3x\n", 1);
 
 gives the follow result:
 
 -01
 001
 -01
 +01
 -01
  01
 0x1
 
 Bruce
Responsible-Changed-From-To: freebsd-bugs->bde 
Responsible-Changed-By: pst 
Responsible-Changed-When: Wed Feb 7 16:09:15 PST 1996 
Responsible-Changed-Why:  
Bruce, _should_ this be fixed?  If not, please close it. 
State-Changed-From-To: open->closed 
State-Changed-By: fenner 
State-Changed-When: Wed Mar 20 10:29:03 PST 1996 
State-Changed-Why:  
Fixed in lib/libc/stdio/vfprintf.c revision 1.8 

>Unformatted:
