"C" character set (again)

Corinna Vinschen corinna-cygwin@cygwin.com
Sat Jan 9 10:38:00 GMT 2010


On Jan  9 06:28, Andy Koppe wrote:
> 2010/1/8 Corinna Vinschen:
> >> But I think it would actually be quite easy to wave invalid bytes
> >> through anyway: print the byte, reset the multibyte conversion state,
> >> and continue processing the string. Still valid according to POSIX,
> >> but also Linux-compatible. I'll propose a patch.
> >
> > I hacked a patch already yesterday:
> 
> Cool. Got round to trying it now.
> 
> > Index: libc/stdio/vfprintf.c
> > ===================================================================
> > RCS file: /cvs/src/src/newlib/libc/stdio/vfprintf.c,v
> > retrieving revision 1.76
> > diff -u -p -r1.76 vfprintf.c
> > --- libc/stdio/vfprintf.c       18 Nov 2009 09:49:56 -0000      1.76
> > +++ libc/stdio/vfprintf.c       8 Jan 2010 12:47:31 -0000
> > @@ -724,8 +724,12 @@ _DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap)
> >                cp = fmt;
> >  #ifdef _MB_CAPABLE
> >                while ((n = __mbtowc (data, &wc, fmt, MB_CUR_MAX,
> > -                                     __locale_charset (), &state)) > 0) {
> > -                    if (wc == '%')
> > +                                     __locale_charset (), &state)) != 0) {
> > +                   if (n < 0) {
> > +                       memset (&state, 0, sizeof state);
> > +                       n = 1;
> > +                   }
> > +                    else if (wc == '%')
> >                         break;
> >                     fmt += n;
> >                }
> >
> > It works, but I'm feeling uneasy about this.
> 
> Looks good to me, and works here too. As far as I can see, there's
> nothing down the line (i.e. in  __(s)sprint_r)  that would choke on
> invalid bytes.

Ok, thanks for testing.  I'll propose it upstream.

> (Btw, I was surprised to discover the integer-only variants of the
> printf functions. Those seem rather unnecessary for Cygwin, but I
> guess once they're in it's impossible to throw them out ...)

Yep, they have been exported from Cygwin as well so we shouldn't kick
them out.  They don't hurt (much) anyway.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat



More information about the Cygwin-developers mailing list