[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: From wchar_t to char32_t
|
From: |
Bruno Haible |
|
Subject: |
Re: From wchar_t to char32_t |
|
Date: |
Tue, 11 Jul 2023 00:58:49 +0200 |
Paul Eggert 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.
I have now fixed this problem like this:
@@ -640,11 +652,13 @@ mbs_to_wchar (wint_t *pwc, char const *s, idx_t n, struct
dfa *d)
if (wc == WEOF)
{
- 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;
+ /* nbytes cannot be == (size) -3 here, since we rely on the
+ 'mbrtoc32-regular' module. */
return nbytes;
}
memset (&d->mbs, 0, sizeof d->mbs);
And pushed the attached patch.
0001-dfa-Overcome-wchar_t-limitations.patch
Description: Text Data
- Re: From wchar_t to char32_t, Bruno Haible, 2023/07/01
- Re: From wchar_t to char32_t, Bruno Haible, 2023/07/01
- Re: From wchar_t to char32_t, Bruno Haible, 2023/07/02
- Re: From wchar_t to char32_t, Paul Eggert, 2023/07/02
- Re: From wchar_t to char32_t, Bruno Haible, 2023/07/02
- Re: From wchar_t to char32_t, Paul Eggert, 2023/07/03
- Re: From wchar_t to char32_t, Paul Eggert, 2023/07/03
- Re: From wchar_t to char32_t, Bruno Haible, 2023/07/03
- Re: From wchar_t to char32_t, Paul Eggert, 2023/07/03
- Re: From wchar_t to char32_t, Bruno Haible, 2023/07/04
- Re: From wchar_t to char32_t, Paul Eggert, 2023/07/04
- Re: From wchar_t to char32_t, Bruno Haible, 2023/07/06