On 2023-07-01 07:35, Bruno Haible wrote:
- wchar_t wch;
- size_t nbytes = mbrtowc (&wch, s, n, &d->mbs);
+ char32_t wch;
+ size_t nbytes = mbrtoc32 (&wch, s, n, &d->mbs);
if (0 < nbytes && nbytes < (size_t) -2)
{
*pwc = wch;
+ if (nbytes == (size_t) -3)
+ nbytes = 0;
return nbytes;
That last change doesn't match the comment for the mbs_to_wchar
function, which says that the function always returns a positive int.
Callers depend on this.
Since nbytes cannot be (size_t) -3 on any known implementation, it's not
surprising that this issue wasn't found by testing. And since it'll
likely be a hassle to port the rest of the code to purely-theoretical
platforms where nbytes == (size_t) -3, I suggest instead simply adding a
comment that nbytes cannot be (size_t) -3 there. This would follow the
advice I added to the Gnulib manual recently, here:
https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=e046d5458353f112e78893ca03d855c8a9aa2e39