This is the mail archive of the
newlib@sources.redhat.com
mailing list for the newlib project.
Re: vfprintf multibyte
- From: "J. Johnston" <jjohnstn at redhat dot com>
- To: "Artem B. Bityuckiy" <abityuckiy at yandex dot ru>
- Cc: newlib at sources dot redhat dot com
- Date: Thu, 20 Nov 2003 17:01:05 -0500
- Subject: Re: vfprintf multibyte
- Organization: Red Hat Inc.
- References: <3FBCEA8D.6040801@yandex.ru>
Artem B. Bityuckiy wrote:
Hello.
I offer some optimization.
Look at CVS-Newlib newlib/libc/stdio/vfprintf.c line 553 for example.
mbtowc call is used. This is needed to support multibyte format string.
But usually in newlib such things are placed in #ifdef MB_CAPABLE/#endif
pair. And this is right because it excludes junk code if Newlib is
configured without multibyte support (if MB_CAPABLE isn't defined then
the only multibyte is US_ASCII or, possibly, other 1 byte encoding like
iso-8859-x).
I offer the patch that excludes mbtowc calls if newlib shouldn't support
multibyte.
Please, see, check, comment.
The non-mb code doesn't appear to handle the end of the format string. In the
old code, there is a check if _mbtowc_r returns <= 0 at which point the code
breaks. For the nul terminator, _mbtowc_r will return 0. The replacement code
stops the loop when *fmt is '\0' but it does not check it afterwards. The
code later makes the assumption it is skipping over the format specifier (fmt++)
when this could well be the nul terminator.
-- Jeff J.