Loading...
stdio/FreeBSD/vfwprintf.c.patch Libc-498 Libc-594.1.4
--- Libc/Libc-498/stdio/FreeBSD/vfwprintf.c.patch
+++ Libc/Libc-594.1.4/stdio/FreeBSD/vfwprintf.c.patch
@@ -1,6 +1,6 @@
---- vfwprintf.c.orig	2006-10-01 00:03:16.000000000 -0700
-+++ vfwprintf.c	2006-10-01 00:21:40.000000000 -0700
-@@ -42,6 +42,8 @@
+--- vfwprintf.c.orig	2008-09-07 11:37:54.000000000 -0700
++++ vfwprintf.c	2008-09-07 17:47:18.000000000 -0700
+@@ -42,6 +42,8 @@ static char sccsid[] = "@(#)vfprintf.c	8
  #include <sys/cdefs.h>
  __FBSDID("$FreeBSD: src/lib/libc/stdio/vfwprintf.c,v 1.23 2004/08/26 06:25:28 des Exp $");
  
@@ -9,7 +9,7 @@
  /*
   * Actual wprintf innards.
   *
-@@ -63,12 +65,20 @@
+@@ -63,12 +65,20 @@ __FBSDID("$FreeBSD: src/lib/libc/stdio/v
  #include <string.h>
  #include <wchar.h>
  #include <wctype.h>
@@ -30,7 +30,7 @@
  union arg {
  	int	intarg;
  	u_int	uintarg;
-@@ -96,6 +106,21 @@
+@@ -96,6 +106,21 @@ union arg {
  #endif
  	wint_t	wintarg;
  	wchar_t	*pwchararg;
@@ -52,7 +52,7 @@
  };
  
  /*
-@@ -106,16 +131,20 @@
+@@ -106,16 +131,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 wchar_t *, va_list, union arg **);
  static void	__grow_type_table(int, enum typeid **, int *);
  
-@@ -125,7 +154,7 @@
+@@ -125,7 +154,7 @@ static void	__grow_type_table(int, enum 
   * worries about ungetc buffers and so forth.
   */
  static int
@@ -85,7 +85,7 @@
  {
  	int ret;
  	FILE fake;
-@@ -144,7 +173,7 @@
+@@ -144,7 +173,7 @@ __sbprintf(FILE *fp, const wchar_t *fmt,
  	fake._lbfsize = 0;	/* not actually used, but Just In Case */
  
  	/* do the work, then copy any error status */
@@ -94,7 +94,7 @@
  	if (ret >= 0 && __fflush(&fake))
  		ret = WEOF;
  	if (fake._flags & __SERR)
-@@ -157,7 +186,7 @@
+@@ -157,7 +186,7 @@ __sbprintf(FILE *fp, const wchar_t *fmt,
   * File must already be locked.
   */
  static wint_t
@@ -103,7 +103,7 @@
  {
  	static const mbstate_t initial;
  	mbstate_t mbs;
-@@ -167,10 +196,10 @@
+@@ -167,10 +196,10 @@ __xfputwc(wchar_t wc, FILE *fp)
  	size_t len;
  
  	if ((fp->_flags & __SSTR) == 0)
@@ -116,7 +116,25 @@
  		fp->_flags |= __SERR;
  		return (WEOF);
  	}
-@@ -350,13 +379,14 @@
+@@ -266,7 +295,7 @@ __ultoa(u_long val, wchar_t *endp, int b
+ 		break;
+ 
+ 	default:			/* oops */
+-		abort();
++		LIBC_ABORT("base = %d", base);
+ 	}
+ 	return (cp);
+ }
+@@ -338,7 +367,7 @@ __ujtoa(uintmax_t val, wchar_t *endp, in
+ 		break;
+ 
+ 	default:
+-		abort();
++		LIBC_ABORT("base = %d", base);
+ 	}
+ 	return (cp);
+ }
+@@ -350,13 +379,14 @@ __ujtoa(uintmax_t val, wchar_t *endp, in
   * that the multibyte char. string ends in a null character.
   */
  static wchar_t *
@@ -133,7 +151,7 @@
  
  	if (mbsarg == NULL)
  		return (NULL);
-@@ -374,7 +404,7 @@
+@@ -374,7 +404,7 @@ __mbsconv(char *mbsarg, int prec)
  		insize = nchars = 0;
  		mbs = initial;
  		while (nchars != (size_t)prec) {
@@ -142,7 +160,7 @@
  			if (nconv == 0 || nconv == (size_t)-1 ||
  			    nconv == (size_t)-2)
  				break;
-@@ -399,7 +429,7 @@
+@@ -399,7 +429,7 @@ __mbsconv(char *mbsarg, int prec)
  	p = mbsarg;
  	mbs = initial;
  	while (insize != 0) {
@@ -151,7 +169,7 @@
  		if (nconv == 0 || nconv == (size_t)-1 || nconv == (size_t)-2)
  			break;
  		wcp++;
-@@ -418,6 +448,8 @@
+@@ -418,6 +448,8 @@ __mbsconv(char *mbsarg, int prec)
  /*
   * MT-safe version
   */
@@ -160,7 +178,7 @@
  int
  vfwprintf(FILE * __restrict fp, const wchar_t * __restrict fmt0, va_list ap)
  
-@@ -425,7 +457,21 @@
+@@ -425,7 +457,21 @@ vfwprintf(FILE * __restrict fp, const wc
  	int ret;
  
  	FLOCKFILE(fp);
@@ -183,7 +201,7 @@
  	FUNLOCKFILE(fp);
  	return (ret);
  }
-@@ -474,12 +520,15 @@
+@@ -474,12 +520,15 @@ static int exponent(wchar_t *, int, wcha
  #define	PTRDIFFT	0x800		/* ptrdiff_t */
  #define	INTMAXT		0x1000		/* intmax_t */
  #define	CHARINT		0x2000		/* print char using int format */
@@ -201,7 +219,7 @@
  {
  	wchar_t *fmt;		/* format string */
  	wchar_t ch;		/* character from fmt */
-@@ -507,7 +556,8 @@
+@@ -507,7 +556,8 @@ __vfwprintf(FILE *fp, const wchar_t *fmt
  	 * D:	expchar holds this character; '\0' if no exponent, e.g. %f
  	 * F:	at least two digits for decimal, at least one digit for hex
  	 */
@@ -211,7 +229,7 @@
  	int signflag;		/* true if float is negative */
  	union {			/* floating point arguments %[aAeEfFgG] */
  		double dbl;
-@@ -524,6 +574,11 @@
+@@ -524,6 +574,11 @@ __vfwprintf(FILE *fp, const wchar_t *fmt
  	int nseps;		/* number of group separators with ' */
  	int nrepeats;		/* number of repeats of the last group */
  #endif
@@ -223,7 +241,7 @@
  	u_long	ulval;		/* integer arguments %[diouxX] */
  	uintmax_t ujval;	/* %j, %ll, %q, %t, %z integers */
  	int base;		/* base for [diouxX] conversion */
-@@ -560,7 +615,7 @@
+@@ -560,7 +615,7 @@ __vfwprintf(FILE *fp, const wchar_t *fmt
  	 */
  #define	PRINT(ptr, len)	do {			\
  	for (n3 = 0; n3 < (len); n3++)		\
@@ -232,7 +250,7 @@
  } while (0)
  #define	PAD(howmany, with)	do {		\
  	if ((n = (howmany)) > 0) {		\
-@@ -606,7 +661,7 @@
+@@ -606,13 +661,13 @@ __vfwprintf(FILE *fp, const wchar_t *fmt
  #define	INTMAX_SIZE	(INTMAXT|SIZET|PTRDIFFT|LLONGINT)
  #define SJARG() \
  	(flags&INTMAXT ? GETARG(intmax_t) : \
@@ -241,7 +259,14 @@
  	    flags&PTRDIFFT ? (intmax_t)GETARG(ptrdiff_t) : \
  	    (intmax_t)GETARG(long long))
  #define	UJARG() \
-@@ -640,21 +695,24 @@
+ 	(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))
+ 
+ 	/*
+@@ -640,21 +695,24 @@ __vfwprintf(FILE *fp, const wchar_t *fmt
  		val = GETARG (int); \
  	}
  
@@ -270,7 +295,7 @@
  
  	fmt = (wchar_t *)fmt0;
  	argtable = NULL;
-@@ -678,6 +736,9 @@
+@@ -678,6 +736,9 @@ __vfwprintf(FILE *fp, const wchar_t *fmt
  		}
  		if (ch == '\0')
  			goto done;
@@ -280,7 +305,7 @@
  		fmt++;		/* skip over '%' */
  
  		flags = 0;
-@@ -686,6 +747,9 @@
+@@ -686,6 +747,9 @@ __vfwprintf(FILE *fp, const wchar_t *fmt
  		prec = -1;
  		sign = '\0';
  		ox[1] = '\0';
@@ -290,7 +315,7 @@
  
  rflag:		ch = *fmt++;
  reswitch:	switch (ch) {
-@@ -701,6 +765,11 @@
+@@ -701,6 +765,11 @@ reswitch:	switch (ch) {
  		case '#':
  			flags |= ALT;
  			goto rflag;
@@ -302,7 +327,7 @@
  		case '*':
  			/*-
  			 * ``A negative field width argument is taken as a
-@@ -721,8 +790,8 @@
+@@ -721,8 +790,8 @@ reswitch:	switch (ch) {
  			goto rflag;
  		case '\'':
  			flags |= GROUPING;
@@ -313,7 +338,7 @@
  			goto rflag;
  		case '.':
  			if ((ch = *fmt++) == '*') {
-@@ -796,10 +865,14 @@
+@@ -796,10 +865,14 @@ reswitch:	switch (ch) {
  			flags |= LONGINT;
  			/*FALLTHROUGH*/
  		case 'c':
@@ -329,7 +354,7 @@
  			size = 1;
  			sign = '\0';
  			break;
-@@ -808,6 +881,10 @@
+@@ -808,6 +881,10 @@ reswitch:	switch (ch) {
  			/*FALLTHROUGH*/
  		case 'd':
  		case 'i':
@@ -340,7 +365,7 @@
  			if (flags & INTMAX_SIZE) {
  				ujval = SJARG();
  				if ((intmax_t)ujval < 0) {
-@@ -826,6 +903,12 @@
+@@ -826,6 +903,12 @@ reswitch:	switch (ch) {
  #ifndef NO_FLOATING_POINT
  		case 'a':
  		case 'A':
@@ -353,7 +378,7 @@
  			if (ch == 'a') {
  				ox[1] = 'x';
  				xdigs = xdigs_lower;
-@@ -837,6 +920,12 @@
+@@ -837,6 +920,12 @@ reswitch:	switch (ch) {
  			}
  			if (prec >= 0)
  				prec++;
@@ -366,7 +391,7 @@
  			if (flags & LONGDBL) {
  				fparg.ldbl = GETARG(long double);
  				dtoaresult =
-@@ -848,6 +937,7 @@
+@@ -848,6 +937,7 @@ reswitch:	switch (ch) {
  				    __hdtoa(fparg.dbl, xdigs, prec,
  				        &expt, &signflag, &dtoaend);
  			}
@@ -374,7 +399,7 @@
  			if (prec < 0)
  				prec = dtoaend - dtoaresult;
  			if (expt == INT_MAX)
-@@ -855,11 +945,17 @@
+@@ -855,11 +945,17 @@ reswitch:	switch (ch) {
  			if (convbuf != NULL)
  				free(convbuf);
  			ndig = dtoaend - dtoaresult;
@@ -393,7 +418,7 @@
  			expchar = ch;
  			if (prec < 0)	/* account for digit before decpt */
  				prec = DEFPREC + 1;
-@@ -868,10 +964,22 @@
+@@ -868,10 +964,22 @@ reswitch:	switch (ch) {
  			goto fp_begin;
  		case 'f':
  		case 'F':
@@ -416,7 +441,7 @@
  			expchar = ch - ('g' - 'e');
  			if (prec == 0)
  				prec = 1;
-@@ -880,6 +988,14 @@
+@@ -880,6 +988,14 @@ fp_begin:
  				prec = DEFPREC;
  			if (convbuf != NULL)
  				free(convbuf);
@@ -431,7 +456,7 @@
  			if (flags & LONGDBL) {
  				fparg.ldbl = GETARG(long double);
  				dtoaresult =
-@@ -893,8 +1009,9 @@
+@@ -893,8 +1009,9 @@ fp_begin:
  				if (expt == 9999)
  					expt = INT_MAX;
  			}
@@ -442,7 +467,7 @@
  			freedtoa(dtoaresult);
  fp_common:
  			if (signflag)
-@@ -989,6 +1106,10 @@
+@@ -989,6 +1106,10 @@ fp_common:
  			flags |= LONGINT;
  			/*FALLTHROUGH*/
  		case 'o':
@@ -453,7 +478,7 @@
  			if (flags & INTMAX_SIZE)
  				ujval = UJARG();
  			else
-@@ -1003,6 +1124,10 @@
+@@ -1003,6 +1124,10 @@ fp_common:
  			 * defined manner.''
  			 *	-- ANSI X3J11
  			 */
@@ -464,7 +489,7 @@
  			ujval = (uintmax_t)(uintptr_t)GETARG(void *);
  			base = 16;
  			xdigs = xdigs_lower;
-@@ -1024,7 +1149,7 @@
+@@ -1024,7 +1149,7 @@ fp_common:
  				if ((mbp = GETARG(char *)) == NULL)
  					cp = L"(null)";
  				else {
@@ -473,7 +498,7 @@
  					if (convbuf == NULL) {
  						fp->_flags |= __SERR;
  						goto error;
-@@ -1055,6 +1180,10 @@
+@@ -1055,6 +1180,10 @@ fp_common:
  			flags |= LONGINT;
  			/*FALLTHROUGH*/
  		case 'u':
@@ -484,7 +509,7 @@
  			if (flags & INTMAX_SIZE)
  				ujval = UJARG();
  			else
-@@ -1067,6 +1196,10 @@
+@@ -1067,6 +1196,10 @@ fp_common:
  		case 'x':
  			xdigs = xdigs_lower;
  hex:
@@ -495,7 +520,7 @@
  			if (flags & INTMAX_SIZE)
  				ujval = UJARG();
  			else
-@@ -1092,6 +1225,7 @@
+@@ -1092,6 +1225,7 @@ number:			if ((dprec = prec) >= 0)
  			 * ``The result of converting a zero value with an
  			 * explicit precision of zero is no characters.''
  			 *	-- ANSI X3J11
@@ -503,7 +528,7 @@
  			 */
  			cp = buf + BUF;
  			if (flags & INTMAX_SIZE) {
-@@ -1101,7 +1235,7 @@
+@@ -1101,7 +1235,7 @@ number:			if ((dprec = prec) >= 0)
  					    flags & GROUPING, thousands_sep,
  					    grouping);
  			} else {
@@ -512,9 +537,12 @@
  					cp = __ultoa(ulval, cp, base,
  					    flags & ALT, xdigs,
  					    flags & GROUPING, thousands_sep,
-@@ -1111,6 +1245,11 @@
+@@ -1109,8 +1243,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':
@@ -524,7 +552,7 @@
  		default:	/* "%?" prints ?, unless ? is NUL */
  			if (ch == '\0')
  				goto done;
-@@ -1122,6 +1261,288 @@
+@@ -1122,6 +1261,288 @@ number:			if ((dprec = prec) >= 0)
  			break;
  		}
  
@@ -813,7 +841,7 @@
  		/*
  		 * All reasonable formats wind up here.  At this point, `cp'
  		 * points to a string which (if not flags&LADJUST) should be
-@@ -1177,7 +1598,7 @@
+@@ -1177,7 +1598,7 @@ number:			if ((dprec = prec) >= 0)
  				if (expt <= 0) {
  					PRINT(zeroes, 1);
  					if (prec || flags & ALT)
@@ -822,7 +850,7 @@
  					PAD(-expt, zeroes);
  					/* already handled initial 0's */
  					prec += expt;
-@@ -1203,15 +1624,14 @@
+@@ -1203,15 +1624,14 @@ number:			if ((dprec = prec) >= 0)
  							cp = convbuf + ndig;
  					}
  					if (prec || flags & ALT) {
@@ -840,7 +868,7 @@
  					PRINT(buf, 2);
  					PRINT(cp, ndig-1);
  					PAD(prec - ndig, zeroes);
-@@ -1401,6 +1821,11 @@
+@@ -1401,6 +1821,11 @@ reswitch:	switch (ch) {
  			if (flags & LONGINT)
  				ADDTYPE(T_WINT);
  			else
@@ -852,7 +880,7 @@
  				ADDTYPE(T_INT);
  			break;
  		case 'D':
-@@ -1408,6 +1833,11 @@
+@@ -1408,6 +1833,11 @@ reswitch:	switch (ch) {
  			/*FALLTHROUGH*/
  		case 'd':
  		case 'i':
@@ -864,7 +892,7 @@
  			ADDSARG();
  			break;
  #ifndef NO_FLOATING_POINT
-@@ -1416,8 +1846,14 @@
+@@ -1416,8 +1846,14 @@ reswitch:	switch (ch) {
  		case 'e':
  		case 'E':
  		case 'f':
@@ -879,7 +907,7 @@
  			if (flags & LONGDBL)
  				ADDTYPE(T_LONG_DOUBLE);
  			else
-@@ -1446,9 +1882,19 @@
+@@ -1446,9 +1882,19 @@ reswitch:	switch (ch) {
  			flags |= LONGINT;
  			/*FALLTHROUGH*/
  		case 'o':
@@ -899,7 +927,7 @@
  			ADDTYPE(TP_VOID);
  			break;
  		case 'S':
-@@ -1466,6 +1912,11 @@
+@@ -1466,6 +1912,11 @@ reswitch:	switch (ch) {
  		case 'u':
  		case 'X':
  		case 'x':
@@ -911,7 +939,7 @@
  			ADDUARG();
  			break;
  		default:	/* "%?" prints ?, unless ? is NUL */
-@@ -1532,7 +1983,7 @@
+@@ -1532,7 +1983,7 @@ done:
  			(*argtable) [n].sizearg = va_arg (ap, size_t);
  			break;
  		    case TP_SIZET:
@@ -920,7 +948,7 @@
  			break;
  		    case T_INTMAXT:
  			(*argtable) [n].intmaxarg = va_arg (ap, intmax_t);
-@@ -1551,6 +2002,11 @@
+@@ -1551,6 +2002,11 @@ done:
  			(*argtable) [n].longdoublearg = va_arg (ap, long double);
  			break;
  #endif
@@ -932,3 +960,18 @@
  		    case TP_CHAR:
  			(*argtable) [n].pchararg = va_arg (ap, char *);
  			break;
+@@ -1585,12 +2041,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;