From phk@critter.freebsd.dk  Tue Dec 13 13:30:21 2005
Return-Path: <phk@critter.freebsd.dk>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id C7B6516A41F
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 13 Dec 2005 13:30:21 +0000 (GMT)
	(envelope-from phk@critter.freebsd.dk)
Received: from phk.freebsd.dk (phk.freebsd.dk [130.225.244.222])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 52F1543D45
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 13 Dec 2005 13:30:20 +0000 (GMT)
	(envelope-from phk@critter.freebsd.dk)
Received: from critter.freebsd.dk (unknown [192.168.48.2])
	by phk.freebsd.dk (Postfix) with ESMTP id 31EF6BC66
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 13 Dec 2005 13:30:19 +0000 (UTC)
Received: from critter.freebsd.dk (localhost [127.0.0.1])
	by critter.freebsd.dk (8.13.4/8.13.4) with ESMTP id jBDDUIES012564
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 13 Dec 2005 14:30:18 +0100 (CET)
	(envelope-from phk@critter.freebsd.dk)
Received: (from phk@localhost)
	by critter.freebsd.dk (8.13.4/8.13.4/Submit) id jBDDUI5e012563;
	Tue, 13 Dec 2005 14:30:18 +0100 (CET)
	(envelope-from phk)
Message-Id: <200512131330.jBDDUI5e012563@critter.freebsd.dk>
Date: Tue, 13 Dec 2005 14:30:18 +0100 (CET)
From: Poul-Henning Kamp <phk@critter.freebsd.dk>
Reply-To: Poul-Henning Kamp <phk@critter.freebsd.dk>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: libc/gdtoa::__hldtoa() bug
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         90333
>Category:       kern
>Synopsis:       [libc] libc/gdtoa::__hldtoa() bug
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    das
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Dec 13 13:40:02 GMT 2005
>Closed-Date:    Wed Jan 03 05:19:37 GMT 2007
>Last-Modified:  Wed Jan 03 05:19:37 GMT 2007
>Originator:     Poul-Henning Kamp
>Release:        FreeBSD 7.0-CURRENT i386
>Organization:
>Environment:
System: FreeBSD critter.freebsd.dk 7.0-CURRENT FreeBSD 7.0-CURRENT #5: Sat Sep 17 14:53:58 CEST 2005 root@critter.freebsd.dk:/freebsd/src/sys/i386/compile/CRITTER i386


>Description:

  /* You're not supposed to hit this problem */
  
  For some denormalized long double values, a bug in __hldtoa() (called
  from *printf()'s %A format) results in a base 16 digit being rounded
  up from 0xf to 0x10.
  
  When this digit is subsequently converted to string format, an index
  of 10 reaches past the end of the uppper-case hex/char array, picking
  up whatever the code segment happen to contain at that address.
  
  This mostly seem to be some character from the upper half of the
  byte range.
  
  When using the %a format instead of %A, the first character past
  the end of the lowercase hex/char table happens to be index 0 in
  the uppercase hex/char table hextable and therefore the string
  representation features a '0', which is supposedly correct.
  
  This leads me to belive that the proper fix _may_ be as simple as
  masking all but the lower four bits off after incrementing a hex-digit
  in libc/gdtoa/_hdtoa.c:roundup().  I worry however that the upper
  bit in 0x10 indicates a carry not carried.
  
  Until das@ or bde@ finds time to visit this issue, extend the
  hexdigit arrays with a 17th index containing '?' so that we get a
  invalid but consistent and printable output in both %a and %A formats
  whenever this bug strikes.
  
  This unmasks the bug in the %a format therefore solving the real
  issue may both become easier and more urgent.
  
  Possibly related to:    PR 85080
  With help by:           bde@
  
  Revision  Changes    Path
  1.71      +2 -2      src/lib/libc/stdio/vfprintf.c

>How-To-Repeat:


	#include <ieeefp.h>
	#include <stdio.h>
	#include <math.h>
	#include <vis.h>

	static void
	pri(const char *fmt, double d)
	{
		char buf[BUFSIZ], buf2[BUFSIZ];

		sprintf(buf, fmt, d, d, d, d);
		strvis(buf2, buf, VIS_OCTAL);
		printf("[%s]\n", buf2);
	}

	int
	main(int argc, char **argv)
	{
		long double x, y;
		int i;

		pri("%-.1LA", 1.0);
		pri("%-.21LA", 1.0);

		fpsetprec(FP_PE);
		x = 0xF.FC0000000000000000000p-1022;
		y = pow(2.0, -1022.0);
		y *= y;			/* -2044 */
		y *= y;			/* -4088 */
		y *= y;			/* -8176 */
		y *= y;			/* -16352 */
		y *= pow(2.0, -35.0);	/* -16387 */
		y *= pow(2.0, 1022.0);	/* -16387+1022 */
		x *= y;			/* 0XF.FC0000000000000000000p-16387 degcc'ed */
		printf("%-.1LA\n", x);
		return (0);
	}

>Fix:

	


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->das 
Responsible-Changed-By: phk 
Responsible-Changed-When: Tue Dec 13 13:58:50 UTC 2005 
Responsible-Changed-Why:  
over to das@ 

http://www.freebsd.org/cgi/query-pr.cgi?pr=90333 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/90333: commit references a PR
Date: Wed,  3 Jan 2007 04:58:13 +0000 (UTC)

 das         2007-01-03 04:57:58 UTC
 
   FreeBSD src repository
 
   Modified files:
     lib/libc/gdtoa       _hdtoa.c 
     lib/libc/stdio       vfprintf.c 
   Log:
   Fix rounding of 0xf for hex fp formats.
   
   PR:     90333
   
   Revision  Changes    Path
   1.4       +1 -1      src/lib/libc/gdtoa/_hdtoa.c
   1.75      +2 -2      src/lib/libc/stdio/vfprintf.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->closed 
State-Changed-By: das 
State-Changed-When: Wed Jan 3 05:19:01 UTC 2007 
State-Changed-Why:  
Fixed in 
1.4       +1 -1      src/lib/libc/gdtoa/_hdtoa.c 
1.75      +2 -2      src/lib/libc/stdio/vfprintf.c 

http://www.freebsd.org/cgi/query-pr.cgi?pr=90333 
>Unformatted:
