2009-02-18 Jeff Johnston <jjohnstn@redhat.com>

* libc/stdio/open_memstream.c (internal_open_memstream_r): Fix max
        buffer size to be in wchar_t units if wide == 1 is passed in.  In
        this case, also initialize the first character of the buffer to be
        wide char null.
        (_open_wmemstream_r): Cast buf to be (char **) to avoid warning.
        * libc/stdlib/mbtowc_r.c (_mbtowc_r): Change all occurences of
        incrementing the size_t value n to first check that n is not already
        size_t -1.  Fix some compiler warnings.
        * libc/stdlib/wcstod.c: Add includes for <wctype.h> and <math.h>.
This commit is contained in:
Jeff Johnston 2009-02-18 21:28:41 +00:00
parent 15fc34ac5a
commit 3f60f7e544
4 changed files with 36 additions and 17 deletions

View File

@ -1,3 +1,15 @@
2009-02-18 Jeff Johnston <jjohnstn@redhat.com>
* libc/stdio/open_memstream.c (internal_open_memstream_r): Fix max
buffer size to be in wchar_t units if wide == 1 is passed in. In
this case, also initialize the first character of the buffer to be
wide char null.
(_open_wmemstream_r): Cast buf to be (char **) to avoid warning.
* libc/stdlib/mbtowc_r.c (_mbtowc_r): Change all occurences of
incrementing the size_t value n to first check that n is not already
size_t -1. Fix some compiler warnings.
* libc/stdlib/wcstod.c: Add includes for <wctype.h> and <math.h>.
2009-02-18 Corinna Vinschen <corinna@vinschen.de>
* libc/stdio/open_memstream.c: Add open_wmemstream to doumentation.

View File

@ -325,6 +325,8 @@ _DEFUN(internal_open_memstream_r, (ptr, buf, size, wide),
mallocs on small strings) and 64k bytes (to avoid overusing the
heap if *size was garbage). */
c->max = *size;
if (wide == 1)
c->max *= sizeof(wchar_t);
if (c->max < 64)
c->max = 64;
else if (c->max > 64 * 1024)
@ -342,7 +344,10 @@ _DEFUN(internal_open_memstream_r, (ptr, buf, size, wide),
_free_r (ptr, c);
return NULL;
}
**buf = '\0';
if (wide == 1)
**((wchar_t **)buf) = L'\0';
else
**buf = '\0';
c->storage = c;
c->pbuf = buf;
@ -374,7 +379,7 @@ _DEFUN(_open_memstream_r, (ptr, buf, size),
char **buf _AND
size_t *size)
{
internal_open_memstream_r (ptr, buf, size, -1);
return internal_open_memstream_r (ptr, buf, size, -1);
}
FILE *
@ -383,7 +388,7 @@ _DEFUN(_open_wmemstream_r, (ptr, buf, size),
wchar_t **buf _AND
size_t *size)
{
internal_open_memstream_r (ptr, buf, size, 1);
return internal_open_memstream_r (ptr, (char **)buf, size, 1);
}
#ifndef _REENT_ONLY

View File

@ -65,8 +65,7 @@ _DEFUN (_mbtowc_r, (r, pwc, s, n, state),
return -2;
#ifdef _MB_CAPABLE
if (__lc_ctype == NULL ||
(strlen (__lc_ctype) <= 1))
if (strlen (__lc_ctype) <= 1)
{ /* fall-through */ }
else if (!strcmp (__lc_ctype, "C-UTF-8"))
{
@ -80,7 +79,8 @@ _DEFUN (_mbtowc_r, (r, pwc, s, n, state),
ch = t[i++];
else
{
++n;
if (n < (size_t)-1)
++n;
ch = state->__value.__wchb[0];
}
@ -123,7 +123,7 @@ _DEFUN (_mbtowc_r, (r, pwc, s, n, state),
state->__value.__wchb[0] = ch;
if (state->__count == 0)
state->__count = 1;
else
else if (n < (size_t)-1)
++n;
if (n < 2)
return -2;
@ -158,7 +158,7 @@ _DEFUN (_mbtowc_r, (r, pwc, s, n, state),
state->__value.__wchb[0] = ch;
if (state->__count == 0)
state->__count = 1;
else
else if (n < (size_t)-1)
++n;
if (n < 2)
return -2;
@ -171,7 +171,7 @@ _DEFUN (_mbtowc_r, (r, pwc, s, n, state),
state->__value.__wchb[1] = ch;
if (state->__count == 1)
state->__count = 2;
else
else if (n < (size_t)-1)
++n;
if (n < 3)
return -2;
@ -201,7 +201,7 @@ _DEFUN (_mbtowc_r, (r, pwc, s, n, state),
state->__value.__wchb[0] = ch;
if (state->__count == 0)
state->__count = 1;
else
else if (n < (size_t)-1)
++n;
if (n < 2)
return -2;
@ -214,7 +214,7 @@ _DEFUN (_mbtowc_r, (r, pwc, s, n, state),
state->__value.__wchb[1] = ch;
if (state->__count == 1)
state->__count = 2;
else
else if (n < (size_t)-1)
++n;
if (n < 3)
return -2;
@ -224,7 +224,7 @@ _DEFUN (_mbtowc_r, (r, pwc, s, n, state),
state->__value.__wchb[2] = ch;
if (state->__count == 2)
state->__count = 3;
else
else if (n < (size_t)-1)
++n;
if (n < 4)
return -2;
@ -254,7 +254,7 @@ _DEFUN (_mbtowc_r, (r, pwc, s, n, state),
state->__value.__wchb[0] = ch;
if (state->__count == 0)
state->__count = 1;
else
else if (n < (size_t)-1)
++n;
if (n < 2)
return -2;
@ -267,7 +267,7 @@ _DEFUN (_mbtowc_r, (r, pwc, s, n, state),
state->__value.__wchb[1] = ch;
if (state->__count == 1)
state->__count = 2;
else
else if (n < (size_t)-1)
++n;
if (n < 3)
return -2;
@ -277,7 +277,7 @@ _DEFUN (_mbtowc_r, (r, pwc, s, n, state),
state->__value.__wchb[2] = ch;
if (state->__count == 2)
state->__count = 3;
else
else if (n < (size_t)-1)
++n;
if (n < 4)
return -2;
@ -287,7 +287,7 @@ _DEFUN (_mbtowc_r, (r, pwc, s, n, state),
state->__value.__wchb[3] = ch;
if (state->__count == 3)
state->__count = 4;
else
else if (n < (size_t)-1)
++n;
if (n < 5)
return -2;
@ -444,7 +444,7 @@ _DEFUN (_mbtowc_r, (r, pwc, s, n, state),
*pwc = (((wchar_t)state->__value.__wchb[0]) << 8) + (wchar_t)(t[i]);
return (i + 1);
case MAKE_A:
ptr = (char *)(t + i + 1);
ptr = (unsigned char *)(t + i + 1);
break;
case ERROR:
default:

View File

@ -117,6 +117,8 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
#include <errno.h>
#include <stdlib.h>
#include <wchar.h>
#include <wctype.h>
#include <math.h>
double
_DEFUN (_wcstod_r, (ptr, nptr, endptr),