Re: an mbrtoc32 bug

2024-05-23 Thread Bruno Haible via Cygwin
The test case that I sent uses UTF-8 encoding.

Here's another test case, that uses GB18030 (supposedly supported
since Cygwin 3.5.0). It fails as well, in line 26.

On glibc systems, this test works.

#include 
#include 
#include 
#include 
#include 
#include 
#include 

int main ()
{
  assert (setlocale (LC_ALL, "zh_CN.GB18030") != NULL);
  mbstate_t state;
  memset (, 0, sizeof (state));

  char32_t uc = 0xDEADBEEF;
  size_t bytes;

  /* \224\071\311\067 = U+0001F403 */
  bytes = mbrtoc32 (, "\224", 1, );
  assert (bytes == (size_t)-2);
  bytes = mbrtoc32 (, "\071", 1, );
  assert (bytes == (size_t)-2);
  bytes = mbrtoc32 (, "\311", 1, );
  assert (bytes == (size_t)-2);
  bytes = mbrtoc32 (, "\067", 1, );
  assert (bytes == 1);
  assert (uc == 0x0001F403);
}

/* Works in: glibc
   Fails in: Cygwin 3.5.3
 */

-- 
Problem reports:  https://cygwin.com/problems.html
FAQ:  https://cygwin.com/faq/
Documentation:https://cygwin.com/docs.html
Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple


an mbrtoc32 bug

2024-05-23 Thread Bruno Haible via Cygwin
In Cygwin 3.5.3, the attached program has an assertion failure in line 24:
bytes is not (size_t)-2.

How to reproduce:
$ gcc -Wall foo.c
$ ./a

I think this is a bug, because
  - ISO C 23 ยง 7.30.1.5 talks about "completing" a character, not
"representing" an (entire) character.
  - The test passes on glibc, musl libc, FreeBSD 14.0, Solaris 11.4.

Bruno

#include 
#include 
#include 
#include 
#include 
#include 
#include 

int main ()
{
  assert (setlocale (LC_ALL, "en_US.UTF-8") != NULL);
  mbstate_t state;
  memset (, 0, sizeof (state));

  char32_t uc = 0xDEADBEEF;
  size_t bytes;

  /* \360\237\220\203 = U+0001F403 */
  bytes = mbrtoc32 (, "\360", 1, );
  assert (bytes == (size_t)-2);
  bytes = mbrtoc32 (, "\237", 1, );
  assert (bytes == (size_t)-2);
  bytes = mbrtoc32 (, "\220", 1, );
  assert (bytes == (size_t)-2);
  bytes = mbrtoc32 (, "\203", 1, );
  assert (bytes == 1);
  assert (uc == 0x0001F403);
}

/* Works in: glibc, musl libc, FreeBSD 14.0, Solaris 11.4
   Fails in: Cygwin 3.5.3
 */

-- 
Problem reports:  https://cygwin.com/problems.html
FAQ:  https://cygwin.com/faq/
Documentation:https://cygwin.com/docs.html
Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple