* iconv/loop.c: Use CLEAR_STATE if defined to clear __state element.
This commit is contained in:
Ulrich Drepper 2003-01-16 07:21:24 +00:00
parent ea31b613fe
commit 41f112ad22
3 changed files with 14 additions and 5 deletions

View File

@ -3,6 +3,7 @@
* iconv/gconv_simple.c (STORE_REST): Explicitly store the total * iconv/gconv_simple.c (STORE_REST): Explicitly store the total
expected size into state. expected size into state.
(UNPACK_BYTES): Do the reverse. (UNPACK_BYTES): Do the reverse.
* iconv/loop.c: Use CLEAR_STATE if defined to clear __state element.
* wcsmbs/tst-mbrtowc.c (utf8_test_1): Add test for the bug. * wcsmbs/tst-mbrtowc.c (utf8_test_1): Add test for the bug.
Reported by Al Viro <aviro@redhat.com>. Reported by Al Viro <aviro@redhat.com>.

View File

@ -1081,7 +1081,7 @@ ucs4le_internal_loop_single (struct __gconv_step *step,
ch <<= r * 6; \ ch <<= r * 6; \
\ \
/* Store the number of bytes expected for the entire sequence. */ \ /* Store the number of bytes expected for the entire sequence. */ \
ch = ch << 3 | cnt; \ state->__count |= cnt << 8; \
\ \
/* Store the value. */ \ /* Store the value. */ \
state->__value.__wch = ch; \ state->__value.__wch = ch; \
@ -1091,10 +1091,9 @@ ucs4le_internal_loop_single (struct __gconv_step *step,
{ \ { \
static const unsigned char inmask[5] = { 0xc0, 0xe0, 0xf0, 0xf8, 0xfc }; \ static const unsigned char inmask[5] = { 0xc0, 0xe0, 0xf0, 0xf8, 0xfc }; \
wint_t wch = state->__value.__wch; \ wint_t wch = state->__value.__wch; \
size_t ntotal = wch & 7; \ size_t ntotal = state->__count >> 8; \
wch >>= 3; \
\ \
inlen = state->__count; \ inlen = state->__count & 255; \
\ \
bytebuf[0] = inmask[ntotal - 2]; \ bytebuf[0] = inmask[ntotal - 2]; \
\ \
@ -1109,6 +1108,10 @@ ucs4le_internal_loop_single (struct __gconv_step *step,
bytebuf[0] |= wch; \ bytebuf[0] |= wch; \
} }
#define CLEAR_STATE \
state->__count = 0
#include <iconv/loop.c> #include <iconv/loop.c>
#include <iconv/skeleton.c> #include <iconv/skeleton.c>

View File

@ -1,5 +1,5 @@
/* Conversion loop frame work. /* Conversion loop frame work.
Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. Copyright (C) 1998-2002, 2003 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
@ -428,7 +428,11 @@ SINGLE(LOOPFCT) (struct __gconv_step *step,
result = __GCONV_OK; result = __GCONV_OK;
/* Clear the state buffer. */ /* Clear the state buffer. */
#ifdef CLEAR_STATE
CLEAR_STATE;
#else
state->__count &= ~7; state->__count &= ~7;
#endif
} }
else if (result == __GCONV_INCOMPLETE_INPUT) else if (result == __GCONV_INCOMPLETE_INPUT)
{ {
@ -479,6 +483,7 @@ gconv_btowc (struct __gconv_step *step, unsigned char c)
#undef UPDATE_PARAMS #undef UPDATE_PARAMS
#undef ONEBYTE_BODY #undef ONEBYTE_BODY
#undef UNPACK_BYTES #undef UNPACK_BYTES
#undef CLEAR_STATE
#undef LOOP_NEED_STATE #undef LOOP_NEED_STATE
#undef LOOP_NEED_FLAGS #undef LOOP_NEED_FLAGS
#undef LOOP_NEED_DATA #undef LOOP_NEED_DATA