This is the mail archive of the 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]

Re: [BUG] wprintf(L"%s", str) expects str to be wide

[Can we please not use top-posting here?  Thanks]

On Jan 11 10:20, Craig Howland wrote:
> On 01/11/2013 10:07 AM, Corinna Vinschen wrote:
> >On Jan 11 09:52, Craig Howland wrote:
> >>Corinna:
> >>     It appears, taking a quick glance at the source, that the string
> >>is only treated as regular characters if _MB_CAPABLE is
> >>defined--otherwise it falls into a wide-character-only case.  This
> >>could perhaps explain the differing results.
> >>                 Craig
> >The _MB_CAPABLE code only handles the case which converts wide chars
> >into multibyte chars.  The default code right after the #endif handles
> >the incoming string as plain byte string.
> >
> Corinna:
>      Are we looking at the same place?  Lines 1200-1217 of
> libc/stdio/vfwprintf.c version 1.10 are what I looked at.  I only
> see wide functions there.  I'll quote from line 1199 to get the
> #endif:
> #endif /* _MB_CAPABLE */
>                         if (prec >= 0) {
>                                 /*
>                                  * can't use wcslen; can only look for the
>                                  * NUL in the first `prec' characters, and
>                                  * strlen () will go further.
>                                  */
>                                 wchar_t *p = wmemchr (cp, L'\0', prec);
>                                 if (p != NULL) {
>                                         size = p - cp;
>                                         if (size > prec)
>                                                 size = prec;
>                                 } else
>                                         size = prec;
>                         } else
>                                 size = wcslen (cp);
>                         break;
> Craig

No, we're not looking at the same code.  I was accidentally looking
into vfprintf.c.  Sorry.

Looking into the right spot now, I don't see how this could be fixed
easily.  _MB_CAPABLE is required to define the conversion functions.
As a fallback we could assume ASCII (or rather ISO-8859-1) and create an
array of UTF wide chars by allocating a temporary wide char array and
fill it with the single byte chars 1:1, but other than that I don't see
a chance.


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]