Bug 22744 - wcwidth glibc issue for 0x2630 Unicode character
Summary: wcwidth glibc issue for 0x2630 Unicode character
Status: RESOLVED INVALID
Alias: None
Product: glibc
Classification: Unclassified
Component: localedata (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-01-24 15:53 UTC by Ilia Sechin
Modified: 2020-07-05 17:27 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ilia Sechin 2018-01-24 15:53:02 UTC
$ cat test.c

#include <stdio.h>
#include <wchar.h>
#include <utf8proc.h>
int main() {
    wint_t c = 0x2630;
    printf("wcwidth returns %d\n", wcwidth(c));
    printf("utf8proc_charwidth returns %d\n", utf8proc_charwidth(c));
    return 0;
}

$ ./test
wcwidth returns -1
utf8proc_charwidth returns 2

So glibc in wcwidth() should return 2 for 0x2630 Unicode character.
More info:
https://github.com/source-foundry/Hack/pull/236#issuecomment-345040104
Comment 1 nick black 2020-07-05 17:13:21 UTC
If I add a call to setlocale(LC_ALL, "") with a proper LANG environment variable and installed locale data, I get the expected result (which is 1, and agrees with modern utf8proc):

[schwarzgerat](0) $ cat test.c
#include <stdio.h>
#include <locale.h>
#include <wchar.h>
#include <utf8proc.h>
int main() {
  setlocale(LC_ALL, "");
  wint_t c = 0x2630;
  printf("wcwidth returns %d\n", wcwidth(c));
  printf("utf8proc_charwidth returns %d\n", utf8proc_charwidth(c));
  return 0;
}
[schwarzgerat](0) $ gcc -D_XOPEN_SOURCE test.c -lutf8proc
[schwarzgerat](0) $ ./a.out
wcwidth returns 1
utf8proc_charwidth returns 1
[schwarzgerat](0) $

I believe this bug can be closed. The test program provided requires a setlocale() call to produce the expected result.
Comment 2 Andreas Schwab 2020-07-05 17:27:05 UTC
Without setlocale, you are using the C locale, with the ASCII codeset.