public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* wctomb() accepts out-of-range character in C-locale
@ 2024-03-25  7:45 Jun T
  2024-03-25 10:32 ` Corinna Vinschen
  0 siblings, 1 reply; 9+ messages in thread
From: Jun T @ 2024-03-25  7:45 UTC (permalink / raw)
  To: newlib

Dear newlib developers,
(this is the first time I post to this list)

On recent Cygwin, the following C code output '1' (i.e., wide character
0x80 can be converted into a valid single-byte character in C-locale):

---------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>

int main() {
    char buf[MB_CUR_MAX];
    setlocale(LC_ALL, "C");
    printf("%d\n", wctomb(buf, 0x80));
    return 0;
}
---------------------------------------

On Linux it outputs '-1'.

It seems this is due to the following commit:

------------------------------------------------
commit 8a4318943875cd922601d34e54ce8a83ad2e733c
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Mon Jul 31 12:44:16 2023 +0200

    Revert "* libc/stdlib/mbtowc_r.c (__ascii_mbtowc): Disallow conversion of"

    This reverts commit 2b77087a48ea56e77fca5aeab478c922f6473d7c.

    For some reason lost in time, commit 2b77087a48ea5 introduced
    Cygwin-specific code treating single byte characters outside the
    portable character set as illegal chars.  However, Cygwin was
    always alone with this over-correct behaviour and it leads to
    stuff like gnulib replacing functions defined in Cygwin with
    their own implementation just due to that.
------------------------------------------------

Probably the function __ascii_wctomb() is used not only in C-locale
but also in some other locales, and the commit is for "fixing"
some problems in these locales?
But a wide character >= 0x80 can't be converted into a valid
character in C-loccale (7bit), I think.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-03-27  8:01 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-25  7:45 wctomb() accepts out-of-range character in C-locale Jun T
2024-03-25 10:32 ` Corinna Vinschen
2024-03-25 11:26   ` Bruno Haible
2024-03-25 11:34     ` Corinna Vinschen
2024-03-25 14:07     ` Jun. T
2024-03-25 20:18       ` brian.inglis
2024-03-26  1:43         ` Jun. T
     [not found]           ` <IBDYAS.IT0GDL3WNBOQ@att.net>
2024-03-26 11:48             ` Steven J Abner
2024-03-27  8:01               ` Jun. T

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).