Loading...
stdio/FreeBSD/vfprintf.c.patch Libc-391.1.21 Libc-594.9.1
--- Libc/Libc-391.1.21/stdio/FreeBSD/vfprintf.c.patch
+++ Libc/Libc-594.9.1/stdio/FreeBSD/vfprintf.c.patch
@@ -1,6 +1,6 @@
---- vfprintf.c.orig	2004-11-25 11:38:35.000000000 -0800
-+++ vfprintf.c	2005-11-08 22:43:11.000000000 -0800
-@@ -40,6 +40,8 @@
+--- vfprintf.c.orig	2008-09-07 11:37:54.000000000 -0700
++++ vfprintf.c	2008-09-07 17:33:16.000000000 -0700
+@@ -40,6 +40,8 @@ static char sccsid[] = "@(#)vfprintf.c	8
  #include <sys/cdefs.h>
  __FBSDID("$FreeBSD: src/lib/libc/stdio/vfprintf.c,v 1.68 2004/08/26 06:25:28 des Exp $");
  
@@ -9,7 +9,7 @@
  /*
   * Actual printf innards.
   *
-@@ -58,6 +60,7 @@
+@@ -58,6 +60,7 @@ __FBSDID("$FreeBSD: src/lib/libc/stdio/v
  #include <stdlib.h>
  #include <string.h>
  #include <wchar.h>
@@ -17,7 +17,7 @@
  
  #include <stdarg.h>
  #include "un-namespace.h"
-@@ -66,6 +69,13 @@
+@@ -66,6 +69,13 @@ __FBSDID("$FreeBSD: src/lib/libc/stdio/v
  #include "local.h"
  #include "fvwrite.h"
  
@@ -31,7 +31,7 @@
  union arg {
  	int	intarg;
  	u_int	uintarg;
-@@ -93,6 +103,21 @@
+@@ -93,6 +103,21 @@ union arg {
  #endif
  	wint_t	wintarg;
  	wchar_t	*pwchararg;
@@ -53,7 +53,7 @@
  };
  
  /*
-@@ -103,16 +128,20 @@
+@@ -103,16 +128,20 @@ enum typeid {
  	T_LONG, T_U_LONG, TP_LONG, T_LLONG, T_U_LLONG, TP_LLONG,
  	T_PTRDIFFT, TP_PTRDIFFT, T_SIZET, TP_SIZET,
  	T_INTMAXT, T_UINTMAXT, TP_INTMAXT, TP_VOID, TP_CHAR, TP_SCHAR,
@@ -76,7 +76,7 @@
  static void	__find_arguments(const char *, va_list, union arg **);
  static void	__grow_type_table(int, enum typeid **, int *);
  
-@@ -141,7 +170,7 @@
+@@ -141,7 +170,7 @@ __sprint(FILE *fp, struct __suio *uio)
   * worries about ungetc buffers and so forth.
   */
  static int
@@ -85,7 +85,7 @@
  {
  	int ret;
  	FILE fake;
-@@ -160,7 +189,7 @@
+@@ -160,7 +189,7 @@ __sbprintf(FILE *fp, const char *fmt, va
  	fake._lbfsize = 0;	/* not actually used, but Just In Case */
  
  	/* do the work, then copy any error status */
@@ -94,7 +94,25 @@
  	if (ret >= 0 && __fflush(&fake))
  		ret = EOF;
  	if (fake._flags & __SERR)
-@@ -336,7 +365,7 @@
+@@ -252,7 +281,7 @@ __ultoa(u_long val, char *endp, int base
+ 		break;
+ 
+ 	default:			/* oops */
+-		abort();
++		LIBC_ABORT("base = %d", base);
+ 	}
+ 	return (cp);
+ }
+@@ -324,7 +353,7 @@ __ujtoa(uintmax_t val, char *endp, int b
+ 		break;
+ 
+ 	default:
+-		abort();
++		LIBC_ABORT("base = %d", base);
+ 	}
+ 	return (cp);
+ }
+@@ -336,14 +365,14 @@ __ujtoa(uintmax_t val, char *endp, int b
   * that the wide char. string ends in a null character.
   */
  static char *
@@ -103,7 +121,15 @@
  {
  	static const mbstate_t initial;
  	mbstate_t mbs;
-@@ -354,7 +383,7 @@
+ 	char buf[MB_LEN_MAX];
+ 	wchar_t *p;
+ 	char *convbuf, *mbp;
+-	size_t clen, nbytes;
++	size_t clen = 0, nbytes;
+ 
+ 	/*
+ 	 * Determine the number of bytes to output and allocate space for
+@@ -354,7 +383,7 @@ __wcsconv(wchar_t *wcsarg, int prec)
  		p = wcsarg;
  		mbs = initial;
  		for (;;) {
@@ -112,7 +138,7 @@
  			if (clen == 0 || clen == (size_t)-1 ||
  			    nbytes + clen > prec)
  				break;
-@@ -363,7 +392,7 @@
+@@ -363,7 +392,7 @@ __wcsconv(wchar_t *wcsarg, int prec)
  	} else {
  		p = wcsarg;
  		mbs = initial;
@@ -121,7 +147,7 @@
  		if (nbytes == (size_t)-1)
  			return (NULL);
  	}
-@@ -378,7 +407,7 @@
+@@ -378,7 +407,7 @@ __wcsconv(wchar_t *wcsarg, int prec)
  	p = wcsarg;
  	mbs = initial;
  	while (mbp - convbuf < nbytes) {
@@ -130,7 +156,16 @@
  		if (clen == 0 || clen == (size_t)-1)
  			break;
  		mbp += clen;
-@@ -402,7 +431,21 @@
+@@ -395,6 +424,8 @@ __wcsconv(wchar_t *wcsarg, int prec)
+ /*
+  * MT-safe version
+  */
++__private_extern__ const char *__fix_nogrouping(const char *);
++
+ int
+ vfprintf(FILE * __restrict fp, const char * __restrict fmt0, va_list ap)
+ 
+@@ -402,7 +433,21 @@ vfprintf(FILE * __restrict fp, const cha
  	int ret;
  
  	FLOCKFILE(fp);
@@ -153,7 +188,7 @@
  	FUNLOCKFILE(fp);
  	return (ret);
  }
-@@ -451,12 +494,15 @@
+@@ -451,12 +496,15 @@ static int exponent(char *, int, int);
  #define	PTRDIFFT	0x800		/* ptrdiff_t */
  #define	INTMAXT		0x1000		/* intmax_t */
  #define	CHARINT		0x2000		/* print char using int format */
@@ -171,7 +206,7 @@
  {
  	char *fmt;		/* format string */
  	int ch;			/* character from fmt */
-@@ -502,6 +548,11 @@
+@@ -502,6 +550,11 @@ __vfprintf(FILE *fp, const char *fmt0, v
  	int nseps;		/* number of group separators with ' */
  	int nrepeats;		/* number of repeats of the last group */
  #endif
@@ -183,7 +218,23 @@
  	u_long	ulval;		/* integer arguments %[diouxX] */
  	uintmax_t ujval;	/* %j, %ll, %q, %t, %z integers */
  	int base;		/* base for [diouxX] conversion */
-@@ -633,22 +684,23 @@
+@@ -599,13 +652,13 @@ __vfprintf(FILE *fp, const char *fmt0, v
+ #define	INTMAX_SIZE	(INTMAXT|SIZET|PTRDIFFT|LLONGINT)
+ #define SJARG() \
+ 	(flags&INTMAXT ? GETARG(intmax_t) : \
+-	    flags&SIZET ? (intmax_t)GETARG(size_t) : \
++	    flags&SIZET ? (intmax_t)GETARG(ssize_t) : \
+ 	    flags&PTRDIFFT ? (intmax_t)GETARG(ptrdiff_t) : \
+ 	    (intmax_t)GETARG(long long))
+ #define	UJARG() \
+ 	(flags&INTMAXT ? GETARG(uintmax_t) : \
+ 	    flags&SIZET ? (uintmax_t)GETARG(size_t) : \
+-	    flags&PTRDIFFT ? (uintmax_t)GETARG(ptrdiff_t) : \
++	    flags&PTRDIFFT ? (uintmax_t)(unsigned)GETARG(ptrdiff_t) : \
+ 	    (uintmax_t)GETARG(unsigned long long))
+ 
+ 	/*
+@@ -633,22 +686,24 @@ __vfprintf(FILE *fp, const char *fmt0, v
  		val = GETARG (int); \
  	}
  
@@ -202,6 +253,7 @@
 +		errno = EBADF;
  		return (EOF);
 +	}
++	ORIENT(fp, -1);
  
  	/* optimise fprintf(stderr) (and other unbuffered Unix files) */
  	if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
@@ -211,7 +263,7 @@
  
  	fmt = (char *)fmt0;
  	argtable = NULL;
-@@ -675,6 +727,9 @@
+@@ -675,6 +730,9 @@ __vfprintf(FILE *fp, const char *fmt0, v
  		}
  		if (ch == '\0')
  			goto done;
@@ -221,7 +273,7 @@
  		fmt++;		/* skip over '%' */
  
  		flags = 0;
-@@ -683,6 +738,9 @@
+@@ -683,6 +741,9 @@ __vfprintf(FILE *fp, const char *fmt0, v
  		prec = -1;
  		sign = '\0';
  		ox[1] = '\0';
@@ -231,7 +283,7 @@
  
  rflag:		ch = *fmt++;
  reswitch:	switch (ch) {
-@@ -698,6 +756,11 @@
+@@ -698,6 +759,11 @@ reswitch:	switch (ch) {
  		case '#':
  			flags |= ALT;
  			goto rflag;
@@ -243,18 +295,18 @@
  		case '*':
  			/*-
  			 * ``A negative field width argument is taken as a
-@@ -718,8 +781,8 @@
+@@ -718,8 +784,8 @@ reswitch:	switch (ch) {
  			goto rflag;
  		case '\'':
  			flags |= GROUPING;
 -			thousands_sep = *(localeconv()->thousands_sep);
 -			grouping = localeconv()->grouping;
 +			thousands_sep = *(localeconv_l(loc)->thousands_sep);
-+			grouping = localeconv_l(loc)->grouping;
++			grouping = __fix_nogrouping(localeconv_l(loc)->grouping);
  			goto rflag;
  		case '.':
  			if ((ch = *fmt++) == '*') {
-@@ -793,14 +856,18 @@
+@@ -793,14 +859,18 @@ reswitch:	switch (ch) {
  			flags |= LONGINT;
  			/*FALLTHROUGH*/
  		case 'c':
@@ -275,7 +327,7 @@
  				if (mbseqlen == (size_t)-1) {
  					fp->_flags |= __SERR;
  					goto error;
-@@ -817,6 +884,10 @@
+@@ -817,6 +887,10 @@ reswitch:	switch (ch) {
  			/*FALLTHROUGH*/
  		case 'd':
  		case 'i':
@@ -286,7 +338,7 @@
  			if (flags & INTMAX_SIZE) {
  				ujval = SJARG();
  				if ((intmax_t)ujval < 0) {
-@@ -835,6 +906,12 @@
+@@ -835,6 +909,12 @@ reswitch:	switch (ch) {
  #ifndef NO_FLOATING_POINT
  		case 'a':
  		case 'A':
@@ -299,7 +351,7 @@
  			if (ch == 'a') {
  				ox[1] = 'x';
  				xdigs = xdigs_lower;
-@@ -848,6 +925,12 @@
+@@ -848,6 +928,12 @@ reswitch:	switch (ch) {
  				prec++;
  			if (dtoaresult != NULL)
  				freedtoa(dtoaresult);
@@ -312,7 +364,7 @@
  			if (flags & LONGDBL) {
  				fparg.ldbl = GETARG(long double);
  				dtoaresult = cp =
-@@ -859,6 +942,7 @@
+@@ -859,6 +945,7 @@ reswitch:	switch (ch) {
  				    __hdtoa(fparg.dbl, xdigs, prec,
  				    &expt, &signflag, &dtoaend);
  			}
@@ -320,7 +372,7 @@
  			if (prec < 0)
  				prec = dtoaend - cp;
  			if (expt == INT_MAX)
-@@ -866,6 +950,12 @@
+@@ -866,6 +953,12 @@ reswitch:	switch (ch) {
  			goto fp_common;
  		case 'e':
  		case 'E':
@@ -333,7 +385,7 @@
  			expchar = ch;
  			if (prec < 0)	/* account for digit before decpt */
  				prec = DEFPREC + 1;
-@@ -874,10 +964,22 @@
+@@ -874,10 +967,22 @@ reswitch:	switch (ch) {
  			goto fp_begin;
  		case 'f':
  		case 'F':
@@ -356,7 +408,7 @@
  			expchar = ch - ('g' - 'e');
  			if (prec == 0)
  				prec = 1;
-@@ -886,6 +988,14 @@
+@@ -886,6 +991,14 @@ fp_begin:
  				prec = DEFPREC;
  			if (dtoaresult != NULL)
  				freedtoa(dtoaresult);
@@ -371,7 +423,7 @@
  			if (flags & LONGDBL) {
  				fparg.ldbl = GETARG(long double);
  				dtoaresult = cp =
-@@ -899,6 +1009,7 @@
+@@ -899,6 +1012,7 @@ fp_begin:
  				if (expt == 9999)
  					expt = INT_MAX;
  			}
@@ -379,7 +431,7 @@
  fp_common:
  			if (signflag)
  				sign = '-';
-@@ -993,6 +1104,10 @@
+@@ -993,6 +1107,10 @@ fp_common:
  			flags |= LONGINT;
  			/*FALLTHROUGH*/
  		case 'o':
@@ -390,7 +442,7 @@
  			if (flags & INTMAX_SIZE)
  				ujval = UJARG();
  			else
-@@ -1007,6 +1122,10 @@
+@@ -1007,6 +1125,10 @@ fp_common:
  			 * defined manner.''
  			 *	-- ANSI X3J11
  			 */
@@ -401,7 +453,7 @@
  			ujval = (uintmax_t)(uintptr_t)GETARG(void *);
  			base = 16;
  			xdigs = xdigs_lower;
-@@ -1025,7 +1144,7 @@
+@@ -1025,7 +1147,7 @@ fp_common:
  				if ((wcp = GETARG(wchar_t *)) == NULL)
  					cp = "(null)";
  				else {
@@ -410,7 +462,7 @@
  					if (convbuf == NULL) {
  						fp->_flags |= __SERR;
  						goto error;
-@@ -1056,6 +1175,10 @@
+@@ -1056,6 +1178,10 @@ fp_common:
  			flags |= LONGINT;
  			/*FALLTHROUGH*/
  		case 'u':
@@ -421,7 +473,7 @@
  			if (flags & INTMAX_SIZE)
  				ujval = UJARG();
  			else
-@@ -1068,6 +1191,10 @@
+@@ -1068,6 +1194,10 @@ fp_common:
  		case 'x':
  			xdigs = xdigs_lower;
  hex:
@@ -432,9 +484,29 @@
  			if (flags & INTMAX_SIZE)
  				ujval = UJARG();
  			else
-@@ -1112,6 +1239,11 @@
+@@ -1093,6 +1223,7 @@ number:			if ((dprec = prec) >= 0)
+ 			 * ``The result of converting a zero value with an
+ 			 * explicit precision of zero is no characters.''
+ 			 *	-- ANSI X3J11
++			 * except for %#.0o and zero value
+ 			 */
+ 			cp = buf + BUF;
+ 			if (flags & INTMAX_SIZE) {
+@@ -1102,7 +1233,7 @@ number:			if ((dprec = prec) >= 0)
+ 					    flags & GROUPING, thousands_sep,
+ 					    grouping);
+ 			} else {
+-				if (ulval != 0 || prec != 0)
++				if (ulval != 0 || prec != 0 || (flags & ALT))
+ 					cp = __ultoa(ulval, cp, base,
+ 					    flags & ALT, xdigs,
+ 					    flags & GROUPING, thousands_sep,
+@@ -1110,8 +1241,13 @@ number:			if ((dprec = prec) >= 0)
+ 			}
+ 			size = buf + BUF - cp;
  			if (size > BUF)	/* should never happen */
- 				abort();
+-				abort();
++				LIBC_ABORT("size %d > BUF %d", size, BUF);
  			break;
 +#ifdef VECTORS
 +		case 'v':
@@ -444,7 +516,7 @@
  		default:	/* "%?" prints ?, unless ? is NUL */
  			if (ch == '\0')
  				goto done;
-@@ -1123,6 +1255,290 @@
+@@ -1123,6 +1259,290 @@ number:			if ((dprec = prec) >= 0)
  			break;
  		}
  
@@ -735,7 +807,34 @@
  		/*
  		 * All reasonable formats wind up here.  At this point, `cp'
  		 * points to a string which (if not flags&LADJUST) should be
-@@ -1406,6 +1822,11 @@
+@@ -1178,7 +1598,7 @@ number:			if ((dprec = prec) >= 0)
+ 				if (expt <= 0) {
+ 					PRINT(zeroes, 1);
+ 					if (prec || flags & ALT)
+-						PRINT(decimal_point, 1);
++						PRINT(decimal_point, strlen(decimal_point));
+ 					PAD(-expt, zeroes);
+ 					/* already handled initial 0's */
+ 					prec += expt;
+@@ -1203,14 +1623,14 @@ number:			if ((dprec = prec) >= 0)
+ 							cp = dtoaend;
+ 					}
+ 					if (prec || flags & ALT)
+-						PRINT(decimal_point,1);
++						PRINT(decimal_point, strlen(decimal_point));
+ 				}
+ 				PRINTANDPAD(cp, dtoaend, prec, zeroes);
+ 			} else {	/* %[eE] or sufficiently long %[gG] */
+ 				if (prec > 1 || flags & ALT) {
+ 					buf[0] = *cp++;
+-					buf[1] = *decimal_point;
+-					PRINT(buf, 2);
++					PRINT(buf, 1);
++					PRINT(decimal_point, strlen(decimal_point));
+ 					PRINT(cp, ndig-1);
+ 					PAD(prec - ndig, zeroes);
+ 				} else	/* XeYYY */
+@@ -1406,6 +1826,11 @@ reswitch:	switch (ch) {
  			if (flags & LONGINT)
  				ADDTYPE(T_WINT);
  			else
@@ -747,7 +846,7 @@
  				ADDTYPE(T_INT);
  			break;
  		case 'D':
-@@ -1413,6 +1834,11 @@
+@@ -1413,6 +1838,11 @@ reswitch:	switch (ch) {
  			/*FALLTHROUGH*/
  		case 'd':
  		case 'i':
@@ -759,8 +858,11 @@
  			ADDSARG();
  			break;
  #ifndef NO_FLOATING_POINT
-@@ -1423,6 +1849,11 @@
+@@ -1421,8 +1851,14 @@ reswitch:	switch (ch) {
+ 		case 'e':
+ 		case 'E':
  		case 'f':
++		case 'F':
  		case 'g':
  		case 'G':
 +#ifdef VECTORS
@@ -771,7 +873,7 @@
  			if (flags & LONGDBL)
  				ADDTYPE(T_LONG_DOUBLE);
  			else
-@@ -1451,9 +1882,19 @@
+@@ -1451,9 +1887,19 @@ reswitch:	switch (ch) {
  			flags |= LONGINT;
  			/*FALLTHROUGH*/
  		case 'o':
@@ -791,7 +893,7 @@
  			ADDTYPE(TP_VOID);
  			break;
  		case 'S':
-@@ -1471,6 +1912,11 @@
+@@ -1471,6 +1917,11 @@ reswitch:	switch (ch) {
  		case 'u':
  		case 'X':
  		case 'x':
@@ -803,7 +905,7 @@
  			ADDUARG();
  			break;
  		default:	/* "%?" prints ?, unless ? is NUL */
-@@ -1537,7 +1983,7 @@
+@@ -1537,7 +1988,7 @@ done:
  			(*argtable) [n].sizearg = va_arg (ap, size_t);
  			break;
  		    case TP_SIZET:
@@ -812,7 +914,7 @@
  			break;
  		    case T_INTMAXT:
  			(*argtable) [n].intmaxarg = va_arg (ap, intmax_t);
-@@ -1556,6 +2002,11 @@
+@@ -1556,6 +2007,11 @@ done:
  			(*argtable) [n].longdoublearg = va_arg (ap, long double);
  			break;
  #endif
@@ -824,3 +926,18 @@
  		    case TP_CHAR:
  			(*argtable) [n].pchararg = va_arg (ap, char *);
  			break;
+@@ -1590,12 +2046,12 @@ __grow_type_table (int nextarg, enum typ
+ 		newsize = nextarg + 1;
+ 	if (oldsize == STATIC_ARG_TBL_SIZE) {
+ 		if ((newtable = malloc(newsize * sizeof(enum typeid))) == NULL)
+-			abort();			/* XXX handle better */
++			LIBC_ABORT("malloc: %s", strerror(errno));			/* XXX handle better */
+ 		bcopy(oldtable, newtable, oldsize * sizeof(enum typeid));
+ 	} else {
+ 		newtable = reallocf(oldtable, newsize * sizeof(enum typeid));
+ 		if (newtable == NULL)
+-			abort();			/* XXX handle better */
++			LIBC_ABORT("reallocf: %s", strerror(errno));			/* XXX handle better */
+ 	}
+ 	for (n = oldsize; n < newsize; n++)
+ 		newtable[n] = T_UNUSED;