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

Jeff Johnston jjohnstn@redhat.com
Tue Jan 19 23:17:00 GMT 2010

On 19/01/10 04:15 PM, Corinna Vinschen wrote:
> Jeff?  Ping?
> On Jan 12 22:10, Andy Koppe wrote:
>> 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
>> http://www.opengroup.org/onlinepubs/000095399/functions/fscanf.html
>> 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.)
>> ChangeLog:
>>          * libc/stdio/vfscanf.c (__SVFSCANF_R): Fix handling of non-ASCII
>>          characters and allow invalid bytes in format string.
>> Andy

Patch applied.

-- Jeff J.

More information about the Newlib mailing list