#497525 libc6: fgetws treats C locale wrongly

Package:
libc6
Source:
glibc
Description:
GNU C Library: Shared libraries
Submitter:
Jonathan David Amery
Date:
2019-10-05 08:03:05 UTC
Severity:
normal
#497525#5
Date:
2008-09-02 11:02:13 UTC
From:
To:
 In the C locale all byte sequences are valid, however using the
following test programme:

#include <stdio.h>
#include <wchar.h>
#include <errno.h>
#include <stdlib.h>
#include <locale.h>

int main() {
  size_t buflen = 512;
  wchar_t *p = malloc(buflen*sizeof(wchar_t));

  setlocale(LC_ALL, "");

  fgetws(p, buflen, stdin);

  if (ferror(stdin)) {
    printf("%s\n", strerror(errno));
    return(1);
  }
  else {
    printf("OK\n");
    return(0);
  }
}

we get:

: ; perl -e 'printf "%c", 0xa1' | env - LC_ALL=C ~/test
Invalid or incomplete multibyte or wide character

0xa1 is of course neither a multibyte or wide character in the C
locale, and fgetws should just read it in the appropriate manner to
allow propagation of it in the same form throughout the programme.