+2023-09-13 Bruno Haible <bruno@clisp.org>
+
+ mbfile: Fix major bug (regression 2023-07-04).
+ Reported by Gleb Fotengauer-Malinovskiy <glebfm@altlinux.org> in
+ <https://lists.gnu.org/archive/html/bug-gnulib/2023-09/msg00088.html>.
+ * lib/mbfile.h (mbfile_multi_getc): If bytes != -1, -2, -3, add the
+ previous mbf->bufcount to bytes.
+
2023-09-11 Pádraig Brady <P@draigBrady.com>
gnu-web-doc-update: fix updating of manual directory
{
/* Feed the bytes one by one into mbrtoc32. */
bytes = mbrtoc32 (&mbc->wc, &mbf->buf[mbf->bufcount], new_bufcount - mbf->bufcount, &mbf->state);
- mbf->bufcount = new_bufcount;
if (bytes == (size_t) -1)
{
/* An invalid multibyte sequence was encountered. */
+ mbf->bufcount = new_bufcount;
/* Return a single byte. */
bytes = 1;
mbc->wc_valid = false;
else if (bytes == (size_t) -2)
{
/* An incomplete multibyte character. */
+ mbf->bufcount = new_bufcount;
if (mbf->bufcount == MBCHAR_BUF_SIZE)
{
/* An overlong incomplete multibyte sequence was encountered. */
}
else
{
- if (bytes == 0)
+ #if !GNULIB_MBRTOC32_REGULAR
+ if (bytes == (size_t) -3)
{
- /* A null 32-bit wide character was encountered. */
- bytes = 1;
- assert (mbf->buf[0] == '\0');
- assert (mbc->wc == 0);
+ /* The previous multibyte sequence produced an additional 32-bit
+ wide character. */
+ mbf->bufcount = new_bufcount;
+ bytes = 0;
}
- #if !GNULIB_MBRTOC32_REGULAR
- else if (bytes == (size_t) -3)
- /* The previous multibyte sequence produced an additional 32-bit
- wide character. */
- bytes = 0;
+ else
#endif
+ {
+ bytes = mbf->bufcount + bytes;
+ mbf->bufcount = new_bufcount;
+ if (bytes == 0)
+ {
+ /* A null 32-bit wide character was encountered. */
+ bytes = 1;
+ assert (mbf->buf[0] == '\0');
+ assert (mbc->wc == 0);
+ }
+ }
mbc->wc_valid = true;
break;
}