+2023-07-04 Bruno Haible <bruno@clisp.org>
+
+ mbiter, mbuiter, mbfile: Improve state handling after invalid input.
+ * lib/mbiter.h (mbiter_multi_next): After an invalid multibyte sequence
+ was encountered, clear the state.
+ * lib/mbuiter.h (mbuiter_multi_next): Likewise.
+ * lib/mbfile.h (mbfile_multi_getc): Likewise.
+
2023-07-04 Bruno Haible <bruno@clisp.org>
mbchar: Optimize all chars from the POSIX "portable character set".
/* Return a single byte. */
bytes = 1;
mbc->wc_valid = false;
+ /* Allow the next invocation to continue from a sane state. */
+ memset (&mbf->state, '\0', sizeof (mbstate_t));
break;
}
else if (bytes == (size_t) -2)
/* An invalid multibyte sequence was encountered. */
iter->cur.bytes = 1;
iter->cur.wc_valid = false;
- /* Whether to set iter->in_shift = false and reset iter->state
- or not is not very important; the string is bogus anyway. */
+ /* Allow the next invocation to continue from a sane state. */
+ iter->in_shift = false;
+ memset (&iter->state, '\0', sizeof (mbstate_t));
}
else if (iter->cur.bytes == (size_t) -2)
{
/* An invalid multibyte sequence was encountered. */
iter->cur.bytes = 1;
iter->cur.wc_valid = false;
- /* Whether to set iter->in_shift = false and reset iter->state
- or not is not very important; the string is bogus anyway. */
+ /* Allow the next invocation to continue from a sane state. */
+ iter->in_shift = false;
+ memset (&iter->state, '\0', sizeof (mbstate_t));
}
else if (iter->cur.bytes == (size_t) -2)
{