This is the mail archive of the cygwin-developers mailing list for the Cygwin 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]

Re: "C" character set (again)


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.

(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 ...)

Andy

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