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 <assert.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <uchar.h>
#include <wchar.h>

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

  char32_t uc = 0xDEADBEEF;
  size_t bytes;

  /* \360\237\220\203 = U+0001F403 */
  bytes = mbrtoc32 (&uc, "\360", 1, &state);
  assert (bytes == (size_t)-2);
  bytes = mbrtoc32 (&uc, "\237", 1, &state);
  assert (bytes == (size_t)-2);
  bytes = mbrtoc32 (&uc, "\220", 1, &state);
  assert (bytes == (size_t)-2);
  bytes = mbrtoc32 (&uc, "\203", 1, &state);
  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

Reply via email to