diff options
Diffstat (limited to 'newlib/libc/stdio')
-rw-r--r-- | newlib/libc/stdio/getdelim.c | 29 | ||||
-rw-r--r-- | newlib/libc/stdio/vfprintf.c | 9 | ||||
-rw-r--r-- | newlib/libc/stdio/vfscanf.c | 5 |
3 files changed, 27 insertions, 16 deletions
diff --git a/newlib/libc/stdio/getdelim.c b/newlib/libc/stdio/getdelim.c index 8ec9d40c8..64f60ee8c 100644 --- a/newlib/libc/stdio/getdelim.c +++ b/newlib/libc/stdio/getdelim.c @@ -109,21 +109,24 @@ __getdelim (bufptr, n, delim, fp) } } - /* Buffer is too small so reallocate a larger buffer. */ - pos = ptr - buf; - newsize = (*n << 1); - buf = realloc (buf, newsize); - if (buf == NULL) + if (cont) { - cont = 0; - break; - } + /* Buffer is too small so reallocate a larger buffer. */ + pos = ptr - buf; + newsize = (*n << 1); + buf = realloc (buf, newsize); + if (buf == NULL) + { + cont = 0; + break; + } - /* After reallocating, continue in new buffer */ - *bufptr = buf; - *n = newsize; - ptr = buf + pos; - numbytes = newsize - pos; + /* After reallocating, continue in new buffer */ + *bufptr = buf; + *n = newsize; + ptr = buf + pos; + numbytes = newsize - pos; + } } _funlockfile (fp); diff --git a/newlib/libc/stdio/vfprintf.c b/newlib/libc/stdio/vfprintf.c index 8e1efd7bb..3fa23491b 100644 --- a/newlib/libc/stdio/vfprintf.c +++ b/newlib/libc/stdio/vfprintf.c @@ -184,6 +184,8 @@ static char *rcsid = "$Id$"; #include <stdlib.h> #include <string.h> #include <reent.h> +#include <wchar.h> +#include <string.h> #ifdef _HAVE_STDC #include <stdarg.h> @@ -426,7 +428,7 @@ _DEFUN (_VFPRINTF_R, (data, fp, fmt0, ap), struct __siov iov[NIOV];/* ... and individual io vectors */ char buf[BUF]; /* space for %c, %[diouxX], %[eEfgG] */ char ox[2]; /* space for 0x hex-prefix */ - int state = 0; /* mbtowc calls from library must not change state */ + mbstate_t state; /* mbtowc calls from library must not change state */ /* * Choose PADSIZE to trade efficiency vs. size. If larger printf @@ -439,6 +441,7 @@ _DEFUN (_VFPRINTF_R, (data, fp, fmt0, ap), static _CONST char zeroes[PADSIZE] = {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'}; + memset (&state, '\0', sizeof (state)); /* * BEWARE, these `goto error' on error, and PAD uses `n'. */ @@ -1367,7 +1370,7 @@ get_arg (int n, char *fmt, va_list *ap, int *numargs_p, union arg_val *args, STATE state, next_state; ACTION action; int pos, last_arg; - int wc_state = 0; + mbstate_t wc_state; int max_pos_arg = n; enum types { INT, LONG_INT, SHORT_INT, QUAD_INT, CHAR, CHAR_PTR, DOUBLE, LONG_DOUBLE }; @@ -1375,6 +1378,8 @@ get_arg (int n, char *fmt, va_list *ap, int *numargs_p, union arg_val *args, if (*last_fmt != NULL) fmt = *last_fmt; + memset (&wc_state, '\0', sizeof (wc_state)); + /* we need to process either to end of fmt string or until we have actually read the desired parameter from the vararg list. */ while (*fmt && n >= numargs) diff --git a/newlib/libc/stdio/vfscanf.c b/newlib/libc/stdio/vfscanf.c index f6c3c930b..61a901ea3 100644 --- a/newlib/libc/stdio/vfscanf.c +++ b/newlib/libc/stdio/vfscanf.c @@ -107,6 +107,8 @@ Supporting OS subroutines required: #include <stdio.h> #include <stdlib.h> #include <limits.h> +#include <wchar.h> +#include <string.h> #ifdef _HAVE_STDC #include <stdarg.h> #else @@ -257,7 +259,7 @@ __svfscanf_r (rptr, fp, fmt0, ap) char buf[BUF]; /* buffer for numeric conversions */ char *lptr; /* literal pointer */ #ifdef MB_CAPABLE - int state = 0; /* value to keep track of multibyte state */ + mbstate_t state; /* value to keep track of multibyte state */ #endif short *sp; @@ -283,6 +285,7 @@ __svfscanf_r (rptr, fp, fmt0, ap) #ifndef MB_CAPABLE wc = *fmt; #else + memset (&state, '\0', sizeof (state)); nbytes = _mbtowc_r (rptr, &wc, fmt, MB_CUR_MAX, &state); #endif fmt += nbytes; |