393b612
			     BASH PATCH REPORT
393b612
			     =================
393b612
393b612
Bash-Release: 3.2
393b612
Patch-ID: bash32-005
393b612
393b612
Bug-Reported-by:	Stuart Shelton <stuart@openobjects.com>
393b612
Bug-Reference-ID:	<453F7CC8.6030907@openobjects.com>
393b612
Bug-Reference-URL:	http://lists.gnu.org/archive/html/bug-bash/2006-10/msg00127.html
393b612
393b612
Bug-Description:
393b612
393b612
A missing extern declaration for `asprintf' caused `double' arguments to be
393b612
passed as `0', leading to incorrect results.  Additionally, a bug in the
393b612
replacement asprintf/snprintf function caused an infinite loop when passed
393b612
0 arguments to the floating point conversions under some circumstances.
393b612
393b612
Patch:
393b612
393b612
*** ../bash-3.2/builtins/printf.def	Mon Sep 18 08:48:42 2006
393b612
--- builtins/printf.def	Tue Oct 31 08:19:44 2006
393b612
***************
393b612
*** 49,54 ****
393b612
--- 49,60 ----
393b612
  #  define INT_MIN		(-2147483647-1)
393b612
  #endif
393b612
  
393b612
+ #if defined (PREFER_STDARG)
393b612
+ #  include <stdarg.h>
393b612
+ #else
393b612
+ #  include <varargs.h>
393b612
+ #endif
393b612
+ 
393b612
  #include <stdio.h>
393b612
  #include <chartypes.h>
393b612
  
393b612
***************
393b612
*** 151,156 ****
393b612
--- 157,166 ----
393b612
  #define SKIP1 "#'-+ 0"
393b612
  #define LENMODS "hjlLtz"
393b612
  
393b612
+ #ifndef HAVE_ASPRINTF
393b612
+ extern int asprintf __P((char **, const char *, ...)) __attribute__((__format__ (printf, 2, 3)));
393b612
+ #endif
393b612
+ 
393b612
  static void printf_erange __P((char *));
393b612
  static int printstr __P((char *, char *, int, int, int));
393b612
  static int tescape __P((char *, char *, int *));
393b612
393b612
393b612
*** ../bash-3.2/lib/sh/snprintf.c	Thu Apr  6 09:48:40 2006
393b612
--- lib/sh/snprintf.c	Sat Oct 28 00:00:13 2006
393b612
***************
393b612
*** 471,476 ****
393b612
--- 476,483 ----
393b612
  	  10^x ~= r
393b612
   * log_10(200) = 2;
393b612
   * log_10(250) = 2;
393b612
+  *
393b612
+  * NOTE: do not call this with r == 0 -- an infinite loop results.
393b612
   */
393b612
  static int
393b612
  log_10(r)
393b612
***************
393b612
*** 576,583 ****
393b612
      { 
393b612
        integral_part[0] = '0';
393b612
        integral_part[1] = '\0';
393b612
!       fraction_part[0] = '0';
393b612
!       fraction_part[1] = '\0';
393b612
        if (fract)
393b612
  	*fract = fraction_part;
393b612
        return integral_part;
393b612
--- 583,593 ----
393b612
      { 
393b612
        integral_part[0] = '0';
393b612
        integral_part[1] = '\0';
393b612
!       /* The fractional part has to take the precision into account */
393b612
!       for (ch = 0; ch < precision-1; ch++)
393b612
!  	fraction_part[ch] = '0';
393b612
!       fraction_part[ch] = '0';
393b612
!       fraction_part[ch+1] = '\0';
393b612
        if (fract)
393b612
  	*fract = fraction_part;
393b612
        return integral_part;
393b612
***************
393b612
*** 805,810 ****
393b612
--- 815,821 ----
393b612
        PUT_CHAR(*tmp, p);
393b612
        tmp++;
393b612
      }
393b612
+ 
393b612
    PAD_LEFT(p);
393b612
  }
393b612
  
393b612
***************
393b612
*** 972,982 ****
393b612
    if ((p->flags & PF_THOUSANDS) && grouping && (t = groupnum (tmp)))
393b612
      tmp = t;
393b612
  
393b612
    /* calculate the padding. 1 for the dot */
393b612
    p->width = p->width -
393b612
  	    ((d > 0. && p->justify == RIGHT) ? 1:0) -
393b612
  	    ((p->flags & PF_SPACE) ? 1:0) -
393b612
! 	    strlen(tmp) - p->precision - 1;
393b612
    PAD_RIGHT(p);  
393b612
    PUT_PLUS(d, p, 0.);
393b612
    PUT_SPACE(d, p, 0.);
393b612
--- 983,1003 ----
393b612
    if ((p->flags & PF_THOUSANDS) && grouping && (t = groupnum (tmp)))
393b612
      tmp = t;
393b612
  
393b612
+   if ((*p->pf == 'g' || *p->pf == 'G') && (p->flags & PF_ALTFORM) == 0)
393b612
+     {
393b612
+       /* smash the trailing zeros unless altform */
393b612
+       for (i = strlen(tmp2) - 1; i >= 0 && tmp2[i] == '0'; i--)
393b612
+         tmp2[i] = '\0'; 
393b612
+       if (tmp2[0] == '\0')
393b612
+ 	p->precision = 0;
393b612
+     }
393b612
+ 
393b612
    /* calculate the padding. 1 for the dot */
393b612
    p->width = p->width -
393b612
  	    ((d > 0. && p->justify == RIGHT) ? 1:0) -
393b612
  	    ((p->flags & PF_SPACE) ? 1:0) -
393b612
! 	    strlen(tmp) - p->precision -
393b612
! 	    ((p->precision != 0 || (p->flags & PF_ALTFORM)) ? 1 : 0);	/* radix char */
393b612
    PAD_RIGHT(p);  
393b612
    PUT_PLUS(d, p, 0.);
393b612
    PUT_SPACE(d, p, 0.);
393b612
***************
393b612
*** 991,1001 ****
393b612
    if (p->precision != 0 || (p->flags & PF_ALTFORM))
393b612
      PUT_CHAR(decpoint, p);  /* put the '.' */
393b612
  
393b612
-   if ((*p->pf == 'g' || *p->pf == 'G') && (p->flags & PF_ALTFORM) == 0)
393b612
-     /* smash the trailing zeros unless altform */
393b612
-     for (i = strlen(tmp2) - 1; i >= 0 && tmp2[i] == '0'; i--)
393b612
-       tmp2[i] = '\0'; 
393b612
- 
393b612
    for (; *tmp2; tmp2++)
393b612
      PUT_CHAR(*tmp2, p); /* the fraction */
393b612
    
393b612
--- 1012,1017 ----
393b612
***************
393b612
*** 1011,1024 ****
393b612
    char *tmp, *tmp2;
393b612
    int j, i;
393b612
  
393b612
!   if (chkinfnan(p, d, 1) || chkinfnan(p, d, 2))
393b612
      return;	/* already printed nan or inf */
393b612
  
393b612
    GETLOCALEDATA(decpoint, thoussep, grouping);
393b612
    DEF_PREC(p);
393b612
!   j = log_10(d);
393b612
!   d = d / pow_10(j);  /* get the Mantissa */
393b612
!   d = ROUND(d, p);		  
393b612
    tmp = dtoa(d, p->precision, &tmp2);
393b612
  
393b612
    /* 1 for unit, 1 for the '.', 1 for 'e|E',
393b612
--- 1027,1045 ----
393b612
    char *tmp, *tmp2;
393b612
    int j, i;
393b612
  
393b612
!   if (d != 0 && (chkinfnan(p, d, 1) || chkinfnan(p, d, 2)))
393b612
      return;	/* already printed nan or inf */
393b612
  
393b612
    GETLOCALEDATA(decpoint, thoussep, grouping);
393b612
    DEF_PREC(p);
393b612
!   if (d == 0.)
393b612
!     j = 0;
393b612
!   else
393b612
!     {
393b612
!       j = log_10(d);
393b612
!       d = d / pow_10(j);  /* get the Mantissa */
393b612
!       d = ROUND(d, p);		  
393b612
!     }
393b612
    tmp = dtoa(d, p->precision, &tmp2);
393b612
  
393b612
    /* 1 for unit, 1 for the '.', 1 for 'e|E',
393b612
***************
393b612
*** 1076,1081 ****
393b612
--- 1097,1103 ----
393b612
         PUT_CHAR(*tmp, p);
393b612
         tmp++;
393b612
       }
393b612
+ 
393b612
     PAD_LEFT(p);
393b612
  }
393b612
  #endif
393b612
***************
393b612
*** 1358,1364 ****
393b612
  		STAR_ARGS(data);
393b612
  		DEF_PREC(data);
393b612
  		d = GETDOUBLE(data);
393b612
! 		i = log_10(d);
393b612
  		/*
393b612
  		 * for '%g|%G' ANSI: use f if exponent
393b612
  		 * is in the range or [-4,p] exclusively
393b612
--- 1380,1386 ----
393b612
  		STAR_ARGS(data);
393b612
  		DEF_PREC(data);
393b612
  		d = GETDOUBLE(data);
393b612
! 		i = (d != 0.) ? log_10(d) : -1;
393b612
  		/*
393b612
  		 * for '%g|%G' ANSI: use f if exponent
393b612
  		 * is in the range or [-4,p] exclusively
393b612
*** ../bash-3.2/patchlevel.h	Thu Apr 13 08:31:04 2006
393b612
--- patchlevel.h	Mon Oct 16 14:22:54 2006
393b612
***************
393b612
*** 26,30 ****
393b612
     looks for to find the patch level (for the sccs version string). */
393b612
  
393b612
! #define PATCHLEVEL 4
393b612
  
393b612
  #endif /* _PATCHLEVEL_H_ */
393b612
--- 26,30 ----
393b612
     looks for to find the patch level (for the sccs version string). */
393b612
  
393b612
! #define PATCHLEVEL 5
393b612
  
393b612
  #endif /* _PATCHLEVEL_H_ */