two bugs in getlocalename_l
Bruno Haible
bruno@clisp.org
Mon Mar 24 13:12:43 GMT 2025
Hi,
It's good to see the addition of getlocalename_l from POSIX [1] in Cygwin 3.6.0.
[1] https://pubs.opengroup.org/onlinepubs/9799919799/functions/getlocalename_l.html
However, there are two bugs:
1) If the second argument is LC_GLOBAL_LOCALE, the return value is garbage.
How to reproduce:
========================== foo.c ============================
#include <locale.h>
#include <stdio.h>
int main ()
{
const char *ret = getlocalename_l (LC_COLLATE, LC_GLOBAL_LOCALE);
printf ("ret as a pointer = %p\n", ret);
printf ("ret as a string = %s\n", ret);
return 2;
}
===============================================================
$ x86_64-pc-cygwin-gcc -Wall -ggdb foo.c
$ ./a
ret as a pointer = 0x1f
$ echo $?
0
Bug 1: The return value is 0x1f, which is not a valid string.
Bug 2: The second printf, instead of crashing, terminates the
program with exit code 0 (faking successful execution!).
2) If the first value is LC_ALL, the return value is NULL.
This can be seen from cygwin/newlib/libc/locale/getlocalename_l.c.
But POSIX [1] specific a valid return value in this case.
The comments in that source file are also wrong:
- "If
the value is LC_ALL or is not a supported locale category value (see
<<setlocale>>), <<getlocalename_l>> shall fail."
No, that's now how it is specified.
<https://www.austingroupbugs.net/view.php?id=1220> specified it this
way, but <https://www.austingroupbugs.net/view.php?id=1741> added the
LC_ALL support.
- "<<getlocalename_l>> is POSIX-1.2008 since Base Specification Issue 8"
No, it was introduced in POSIX-1.2024.
Bruno
More information about the Cygwin
mailing list