Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2009-07-28 20:49:19 +0400
committerCorinna Vinschen <corinna@vinschen.de>2009-07-28 20:49:19 +0400
commitecf5c883df2c125ca3441898699a6597a6eae141 (patch)
tree38438b4bf08b88787506aa5252fdccff2a099f01 /newlib/libc/stdlib
parent8d641a5b46d3e5903c6f35125a45e23a4cbc8205 (diff)
* libc/stdlib/mbtowc_r.c (__utf8_mbtowc): Fix incrementing n in case
of handling incomplete sequences.
Diffstat (limited to 'newlib/libc/stdlib')
-rw-r--r--newlib/libc/stdlib/mbtowc_r.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/newlib/libc/stdlib/mbtowc_r.c b/newlib/libc/stdlib/mbtowc_r.c
index 010ce1da5..7e1362245 100644
--- a/newlib/libc/stdlib/mbtowc_r.c
+++ b/newlib/libc/stdlib/mbtowc_r.c
@@ -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++];