* libc/stdlib/mbtowc_r.c (__utf8_mbtowc): Fix incrementing n in case

of handling incomplete sequences.
This commit is contained in:
Corinna Vinschen 2009-07-28 16:49:19 +00:00
parent 8d641a5b46
commit ecf5c883df
2 changed files with 18 additions and 8 deletions

View File

@ -1,3 +1,8 @@
2009-07-28 Corinna Vinschen <corinna@vinschen.de>
* libc/stdlib/mbtowc_r.c (__utf8_mbtowc): Fix incrementing n in case
of handling incomplete sequences.
2009-07-22 Eric Blake <ebb9@byu.net>
Avoid a fault from locking a closed standard file.

View File

@ -220,11 +220,7 @@ _DEFUN (__utf8_mbtowc, (r, pwc, s, n, charset, state),
if (state->__count == 0)
ch = t[i++];
else
{
if (n < (size_t)-1)
++n;
ch = state->__value.__wchb[0];
}
ch = state->__value.__wchb[0];
if (ch == '\0')
{
@ -244,7 +240,10 @@ _DEFUN (__utf8_mbtowc, (r, pwc, s, n, charset, state),
{
/* two-byte sequence */
state->__value.__wchb[0] = ch;
state->__count = 1;
if (state->__count == 0)
state->__count = 1;
else if (n < (size_t)-1)
++n;
if (n < 2)
return -2;
ch = t[i++];
@ -288,7 +287,10 @@ _DEFUN (__utf8_mbtowc, (r, pwc, s, n, charset, state),
return -1;
}
state->__value.__wchb[1] = ch;
state->__count = 2;
if (state->__count == 1)
state->__count = 2;
else if (n < (size_t)-1)
++n;
if (n < 3)
return -2;
ch = t[i++];
@ -347,7 +349,10 @@ _DEFUN (__utf8_mbtowc, (r, pwc, s, n, charset, state),
return -1;
}
state->__value.__wchb[2] = ch;
state->__count = 3;
if (state->__count == 2)
state->__count = 3;
else if (n < (size_t)-1)
++n;
if (n < 4)
return -2;
ch = t[i++];