This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch/cygwin] wctomb/mbtowc: Disallow non-ascii conversion


Hi,

I applied the below patch, which is only active on Cygwin for now.

It disallows wctomb/mbtowc conversion in the ASCII charset, if the
character in question is outside of the 7-bit ASCII character range.
The normal behaviour, which I left intact for all other platforms, is to
convert all 8-bit characters to and from wide char.  This is incorrect,
since it makes ASCII identical to ISO-8859-1.  Certain applications
choke on this incorrect behaviour.  The applied patch aligns this
behaviour to other platforms as, for instance, Linux with glibc.

Even though I only changed this for Cygwin right now, I think that this
patch should be applied generically for all platforms.

What do others think?


Corinna


	* libc/stdlib/mbtowc_r.c (__ascii_mbtowc): Disallow conversion of
	non-ASCII chars on Cygwin.
	* libc/stdlib/wctomb_r.c (__ascii_wctomb): Ditto.


Index: libc/stdlib/mbtowc_r.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdlib/mbtowc_r.c,v
retrieving revision 1.18
diff -u -p -r1.18 mbtowc_r.c
--- libc/stdlib/mbtowc_r.c	18 Nov 2009 09:49:57 -0000	1.18
+++ libc/stdlib/mbtowc_r.c	10 Jan 2010 13:53:57 -0000
@@ -47,6 +47,14 @@ _DEFUN (__ascii_mbtowc, (r, pwc, s, n, c
   if (n == 0)
     return -2;
 
+#ifdef __CYGWIN__
+  if ((wchar_t)*t >= 0x80)
+    {
+      r->_errno = EILSEQ;
+      return -1;
+    }
+#endif
+
   *pwc = (wchar_t)*t;
   
   if (*t == '\0')
Index: libc/stdlib/wctomb_r.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdlib/wctomb_r.c,v
retrieving revision 1.16
diff -u -p -r1.16 wctomb_r.c
--- libc/stdlib/wctomb_r.c	3 Oct 2009 08:51:07 -0000	1.16
+++ libc/stdlib/wctomb_r.c	10 Jan 2010 13:53:57 -0000
@@ -40,7 +40,11 @@ _DEFUN (__ascii_wctomb, (r, s, wchar, ch
   if (s == NULL)
     return 0;
  
+#ifdef __CYGWIN__
+  if ((size_t)wchar >= 0x80)
+#else
   if ((size_t)wchar >= 0x100)
+#endif
     {
       r->_errno = EILSEQ;
       return -1;


-- 
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]