summaryrefslogtreecommitdiffstats
path: root/newlib/libc/stdio/vfprintf.c
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2008-04-30 02:47:14 +0000
committerEric Blake <eblake@redhat.com>2008-04-30 02:47:14 +0000
commitf77a1a884885a10a5210a42ad9bff6514eb0c374 (patch)
tree2117fdee5ce76bd659cff7629cb0c9d7b7e24bb9 /newlib/libc/stdio/vfprintf.c
parent661efd2deaf2042829683112411be7f7902abe13 (diff)
downloadcygnal-f77a1a884885a10a5210a42ad9bff6514eb0c374.tar.gz
cygnal-f77a1a884885a10a5210a42ad9bff6514eb0c374.tar.bz2
cygnal-f77a1a884885a10a5210a42ad9bff6514eb0c374.zip
Fix 2008-04-14 regression in asprintf(ptr,"").
* libc/stdio/asnprintf.c (asnprintf, _asnprintf_r): Avoid stdio baggage. * libc/stdio/asniprintf.c (asniprintf, _asniprintf_r): Likewise. * libc/stdio/asiprintf.c (asiprintf, _asiprintf_r): Likewise. * libc/stdio/vasniprintf.c (_vasniprintf_r): Likewise. * libc/stdio/vsnprintf.c (_vsnprintf_r): Likewise. * libc/stdio/vfprintf.c (_VFPRINTF_R) [STRING_ONLY]: Always malloc an initial buffer for asprintf.
Diffstat (limited to 'newlib/libc/stdio/vfprintf.c')
-rw-r--r--newlib/libc/stdio/vfprintf.c54
1 files changed, 33 insertions, 21 deletions
diff --git a/newlib/libc/stdio/vfprintf.c b/newlib/libc/stdio/vfprintf.c
index cfe1e3f4e..1846d7c1e 100644
--- a/newlib/libc/stdio/vfprintf.c
+++ b/newlib/libc/stdio/vfprintf.c
@@ -226,12 +226,12 @@ _DEFUN(__sprint_r, (ptr, fp, uio),
if (!str) {
/* Free unneeded buffer. */
_free_r (ptr, fp->_bf._base);
- /* Ensure correct errno, even if free
+ /* Ensure correct errno, even if free
* changed it. */
ptr->_errno = ENOMEM;
goto err;
}
- }
+ }
fp->_bf._base = str;
fp->_p = str + curpos;
fp->_bf._size = newsize;
@@ -259,7 +259,7 @@ err:
return EOF;
}
-#else /* !STRING_ONLY */
+#else /* !STRING_ONLY */
/*
* Flush out all the vectors defined by the given uio,
* then reset it so that it can be reused.
@@ -425,8 +425,8 @@ union arg_val
};
static union arg_val *
-_EXFUN(get_arg, (struct _reent *data, int n, char *fmt,
- va_list *ap, int *numargs, union arg_val *args,
+_EXFUN(get_arg, (struct _reent *data, int n, char *fmt,
+ va_list *ap, int *numargs, union arg_val *args,
int *arg_type, char **last_fmt));
#endif /* !_NO_POS_ARGS */
@@ -464,7 +464,7 @@ _EXFUN(get_arg, (struct _reent *data, int n, char *fmt,
int _EXFUN(_VFPRINTF_R, (struct _reent *, FILE *, _CONST char *, va_list));
#ifndef STRING_ONLY
-int
+int
_DEFUN(VFPRINTF, (fp, fmt0, ap),
FILE * fp _AND
_CONST char *fmt0 _AND
@@ -476,7 +476,7 @@ _DEFUN(VFPRINTF, (fp, fmt0, ap),
}
#endif /* STRING_ONLY */
-int
+int
_DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap),
struct _reent *data _AND
FILE * fp _AND
@@ -629,7 +629,7 @@ _DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap),
/* sorry, fprintf(read_only_file, "") returns EOF, not 0 */
if (cantwrite (data, fp)) {
- _funlockfile (fp);
+ _funlockfile (fp);
return (EOF);
}
@@ -639,6 +639,18 @@ _DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap),
_funlockfile (fp);
return (__sbprintf (data, fp, fmt0, ap));
}
+#else /* STRING_ONLY */
+ /* Create initial buffer if we are called by asprintf family. */
+ if (fp->_flags & __SMBF && !fp->_bf._base)
+ {
+ fp->_bf._base = fp->_p = _malloc_r (data, 64);
+ if (!fp->_p)
+ {
+ data->_errno = ENOMEM;
+ return EOF;
+ }
+ fp->_bf._size = 64;
+ }
#endif /* STRING_ONLY */
fmt = (char *)fmt0;
@@ -918,7 +930,7 @@ reswitch: switch (ch) {
(wchar_t)GET_ARG (N, ap, wint_t),
&ps)) == -1) {
fp->_flags |= __SERR;
- goto error;
+ goto error;
}
}
else
@@ -1096,7 +1108,7 @@ reswitch: switch (ch) {
#ifndef _NO_LONGLONG
if (flags & QUADINT)
*GET_ARG (N, ap, quad_ptr_t) = ret;
- else
+ else
#endif
if (flags & LONGINT)
*GET_ARG (N, ap, long_ptr_t) = ret;
@@ -1602,7 +1614,7 @@ exponent(char *p0, int exp, int fmtch)
Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
-
+
The name of Red Hat Incorporated may not be used to endorse
or promote products derived from this software without specific
prior written permission.
@@ -1627,24 +1639,24 @@ typedef enum {
DOT, /* '.' */
STAR, /* '*' */
FLAG, /* format flag */
- OTHER, /* all other chars */
+ OTHER, /* all other chars */
MAX_CH_CLASS /* place-holder */
} CH_CLASS;
-typedef enum {
+typedef enum {
START, /* start */
SFLAG, /* seen a flag */
WDIG, /* seen digits in width area */
WIDTH, /* processed width */
SMOD, /* seen spec modifier */
- SDOT, /* seen dot */
+ SDOT, /* seen dot */
VARW, /* have variable width specifier */
VARP, /* have variable precision specifier */
PREC, /* processed precision */
VWDIG, /* have digits in variable width specification */
VPDIG, /* have digits in variable precision specification */
- DONE, /* done */
- MAX_STATE, /* place-holder */
+ DONE, /* done */
+ MAX_STATE, /* place-holder */
} STATE;
typedef enum {
@@ -1669,7 +1681,7 @@ _CONST static CH_CLASS chclass[256] = {
/* 30-37 */ ZERO, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT,
/* 38-3f */ DIGIT, DIGIT, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
/* 40-47 */ OTHER, SPEC, OTHER, SPEC, SPEC, SPEC, SPEC, SPEC,
- /* 48-4f */ OTHER, OTHER, OTHER, OTHER, MODFR, OTHER, OTHER, SPEC,
+ /* 48-4f */ OTHER, OTHER, OTHER, OTHER, MODFR, OTHER, OTHER, SPEC,
/* 50-57 */ OTHER, OTHER, OTHER, SPEC, OTHER, SPEC, OTHER, OTHER,
/* 58-5f */ SPEC, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER, OTHER,
/* 60-67 */ OTHER, SPEC, OTHER, SPEC, SPEC, SPEC, SPEC, SPEC,
@@ -1695,7 +1707,7 @@ _CONST static CH_CLASS chclass[256] = {
};
_CONST static STATE state_table[MAX_STATE][MAX_CH_CLASS] = {
- /* '0' '1-9' '$' MODFR SPEC '.' '*' FLAG OTHER */
+ /* '0' '1-9' '$' MODFR SPEC '.' '*' FLAG OTHER */
/* START */ { SFLAG, WDIG, DONE, SMOD, DONE, SDOT, VARW, SFLAG, DONE },
/* SFLAG */ { SFLAG, WDIG, DONE, SMOD, DONE, SDOT, VARW, SFLAG, DONE },
/* WDIG */ { DONE, DONE, WIDTH, SMOD, DONE, SDOT, DONE, DONE, DONE },
@@ -1710,7 +1722,7 @@ _CONST static STATE state_table[MAX_STATE][MAX_CH_CLASS] = {
};
_CONST static ACTION action_table[MAX_STATE][MAX_CH_CLASS] = {
- /* '0' '1-9' '$' MODFR SPEC '.' '*' FLAG OTHER */
+ /* '0' '1-9' '$' MODFR SPEC '.' '*' FLAG OTHER */
/* START */ { NOOP, NUMBER, NOOP, GETMOD, GETARG, NOOP, NOOP, NOOP, NOOP },
/* SFLAG */ { NOOP, NUMBER, NOOP, GETMOD, GETARG, NOOP, NOOP, NOOP, NOOP },
/* WDIG */ { NOOP, NOOP, GETPOS, GETMOD, GETARG, NOOP, NOOP, NOOP, NOOP },
@@ -1766,10 +1778,10 @@ _DEFUN(get_arg, (data, n, fmt, ap, numargs_p, args, arg_type, last_fmt),
while (*fmt && n >= numargs)
{
# ifdef _MB_CAPABLE
- while ((nbytes = _mbtowc_r (data, &wc, fmt, MB_CUR_MAX, &wc_state)) > 0)
+ while ((nbytes = _mbtowc_r (data, &wc, fmt, MB_CUR_MAX, &wc_state)) > 0)
{
fmt += nbytes;
- if (wc == '%')
+ if (wc == '%')
break;
}