[pechtcha: Bug in scanf &Co (Was Re: Error message from antiword since upgrade to cygwin 1.5.10)]
Jeff Johnston
jjohnstn@redhat.com
Wed Jun 2 20:44:00 GMT 2004
I have checked in a patch. When the 0 was read, some flags were cleared,
however, these flags should have been reset again when the x was found since the
0 was actually part of the hex prefix and not a digit.
-- Jeff J.
Christopher Faylor wrote:
> ----- Forwarded message from Igor Pechtchanski <pechtcha> -----
>
> From: Igor Pechtchanski
> To: cygwin
> Cc: "Gerrit P. Haase"
> Subject: Bug in scanf &Co (Was Re: Error message from antiword since upgrade to cygwin 1.5.10)
> Date: Wed, 2 Jun 2004 14:04:33 -0400 (EDT)
> In-Reply-To: <Pine.GSO.4.58.0406021327090.18478@slinky.cs.nyu.edu>
>
> On Wed, 2 Jun 2004, Igor Pechtchanski wrote:
>
>
>>On Wed, 2 Jun 2004, Gerrit P. Haase wrote:
>>
>>[snip]
>>
>>>Everything works ok with cygwin-1.5.9. I'll try to recompile with
>>>1.5.10 later, maybe that helps...
>>>
>>>Gerrit
>>
>>Try the attached patch. FWIW, it seems like there's a bug here, but
>>sscanf used to mask it. Was there a change in the sscanf implementation
>>since 1.5.9?
>> Igor
>
>
> Never mind. This is a bug in the newlib scanf family implementation
> (actually, in __svfscanf_r in libc/stdio/vfscanf.c) that causes it to read
> strings of the form 0x0+ incorrectly. Attached is a testcase that
> demonstrates the bug. I suspect the following change:
>
> 2004-04-21 J"orn Rennecke
>
> * libc/stdio/vfscanf.c (NNZDIGITS): New define.
> (__svfscanf_r): In integer conversions, leave out leading zeroes
> which are not part of a base prefix.
> Keep track of width truncation to fit into buf, not counting left-out
> zeroes against width till the truncation has been compensated for.
>
> #include <stdlib.h>
> #include <stdio.h>
>
> int main(char ac, char *av[]) {
> const char *str1 = "0x1 0x0 0x3";
> const char *str2 = "0x1 0x2 0x3";
> unsigned int i,j,k;
> sscanf(str1, "%x %x %x", &i, &j, &k);
> printf("Values are: %x %x %x\n", i, j, k);
> sscanf(str2, "%x %x %x", &i, &j, &k);
> printf("Values are: %x %x %x\n", i, j, k);
> }
>
> --
> Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
> Problem reports: http://cygwin.com/problems.html
> Documentation: http://cygwin.com/docs.html
> FAQ: http://cygwin.com/faq/
>
> ----- End forwarded message -----
More information about the Newlib
mailing list