musl/src/multibyte
Rich Felker 23ab8c2555 mbrtowc: do not leave mbstate_t in permanent-fail state after EILSEQ
the standard is clear that the old behavior is conforming: "In this
case, [EILSEQ] shall be stored in errno and the conversion state is
undefined."

however, the specification of mbrtowc has one peculiarity when the
source argument is a null pointer: in this case, it's required to
behave as mbrtowc(NULL, "", 1, ps). no motivation is provided for this
requirement, but the natural one that comes to mind is that the intent
is to reset the mbstate_t object. for stateful encodings, such
behavior is actually specified: "If the corresponding wide character
is the null wide character, the resulting state described shall be the
initial conversion state." but in the case of UTF-8 where the
mbstate_t object contains a partially-decoded character rather than a
shift state, a subsequent '\0' byte indicates that the previous
partial character is incomplete and thus an illegal sequence.

naturally, applications using their own mbstate_t object should clear
it themselves after an error, but the standard presently provides no
way to clear the builtin mbstate_t object used when the ps argument is
a null pointer. I suspect this issue may be addressed in the future by
specifying that a null source argument resets the state, as this seems
to have been the intent all along.

for what it's worth, this change also slightly reduces code size.
2013-04-08 23:09:11 -04:00
..
btowc.c initial check-in, version 0.5.0 2011-02-12 00:22:29 -05:00
internal.c new attempt at working around the gcc 3 visibility bug 2012-02-24 20:07:21 -05:00
internal.h fix out-of-bounds access in UTF-8 decoding 2013-04-08 22:29:46 -04:00
mblen.c initial check-in, version 0.5.0 2011-02-12 00:22:29 -05:00
mbrlen.c use restrict everywhere it's required by c99 and/or posix 2008 2012-09-06 22:44:55 -04:00
mbrtowc.c mbrtowc: do not leave mbstate_t in permanent-fail state after EILSEQ 2013-04-08 23:09:11 -04:00
mbsinit.c fix failure of mbsinit(0) (not UB; required to return nonzero) 2012-05-26 18:02:45 -04:00
mbsnrtowcs.c use restrict everywhere it's required by c99 and/or posix 2008 2012-09-06 22:44:55 -04:00
mbsrtowcs.c overhaul mbsrtowcs 2013-04-04 14:42:35 -04:00
mbstowcs.c cleanup mbstowcs wrapper 2013-04-04 14:53:53 -04:00
mbtowc.c implement mbtowc directly, not as a wrapper for mbrtowc 2013-04-08 23:01:32 -04:00
wcrtomb.c use restrict everywhere it's required by c99 and/or posix 2008 2012-09-06 22:44:55 -04:00
wcsnrtombs.c use restrict everywhere it's required by c99 and/or posix 2008 2012-09-06 22:44:55 -04:00
wcsrtombs.c fix incorrect range checks in wcsrtombs 2013-04-04 14:48:48 -04:00
wcstombs.c cleanup wcstombs 2013-04-04 14:55:42 -04:00
wctob.c initial check-in, version 0.5.0 2011-02-12 00:22:29 -05:00
wctomb.c initial check-in, version 0.5.0 2011-02-12 00:22:29 -05:00