[PATCH] stdio/vfscanf.c: Handle non-ASCII chars and invalid bytes in format string

Andy Koppe andy.koppe@gmail.com
Tue Jan 12 22:10:00 GMT 2010

Similarly to Corinna's patch for vfprintf, here's a patch for vfscanf
that corrects its handling of non-ASCII chars and allows invalid bytes
in the format string.

The code currently has a comparison between a signed and an unsigned
char at line 552, which causes matching of any non-ASCII characters in
the format string to always fail. It also wrongly resets the multibyte
conversion state after every character. (The standard at
says "the format is a character string, beginning and ending in its
initial shift state"). Finally, %lc and %ls conversions use the same
conversion state as is used for the format string, thereby clobbering
the format string state.

The patch addresses those issues and also allows invalid bytes in the
format string to be matched. (Invalid bytes currently cause the format
string parsing to go backwards, since __mbtowc in line 510 will return
-1 in that case.)

        * libc/stdio/vfscanf.c (__SVFSCANF_R): Fix handling of non-ASCII
        characters and allow invalid bytes in format string.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: vfscanf.patch
Type: application/octet-stream
Size: 981 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20100112/c700aeef/attachment.obj>

More information about the Newlib mailing list