sscanf behaviour. bug?

J. Johnston jjohnstn@redhat.com
Thu Mar 20 21:10:00 GMT 2003


The attached patch has been checked in.

-- Jeff J.

J. Johnston wrote:
> I believe I have found the problem.  It is a float-specific error - I do 
> not
> know why you have stated that it occurs for any other conversion 
> descriptor.
> For example, %d instead of %f works as expected.
> 
> I am testing a patch and will post shortly if successful.
> 
> -- Jeff J.
> 
> 
> Hannes Krueger wrote:
> 
>> The following is from a recent thread on comp.lang.c
>> and seems to be a bug in the sscanf implementation of newlib, since 
>> cygwin (with
>> which this behaviour occurs) is using newlib.
>> I had a look in the newlib-sources, but I wasnt able to locate this 
>> problem.
>> Maybe someone else is able to?!
>>
>> regards
>> Hannes
>>
>> the following is copied from the newsgroup:
>>
>> ---
>>
>> In <3e703aa8$1@sia.uibk.ac.at> student <student@dont.like.spam> writes:
>>
>>
>>
>>>> I encountered some strange sscanf-behaviour.
>>>>
>>>> this is the line I want to parse:
>>>> B0927035313520....
>>>>
>>>> I want to read fixed columns.
>>>>
>>>> sscanf(line, "%*c%2lf%2lf%2lf ...." , &val1, &val2, &val3 ....
>>>>
>>>> when I compile in a linux gnu environment I get
>>>> val1 = 9
>>>> val2 = 27
>>>> val3 = 3
>>>
>>>
>>
>>
>> This is the correct behaviour.  %f (or any other conversion descriptor,
>> for that matter) does not allow the suppression of zeros before the
>> start of the conversion.
>>
>>
>>
>>>> But when I compile under cygwin (gcc 3.2) on windows I get
>>>> val1 = 92
>>>> val2 = 70
>>>> val3 = 35
>>>
>>>
>>
>>
>> This is broken behaviour.  You have specified a *maximum* field length
>> of 2, but the first conversion used 3 characters.
>>
>>
>>
>>>> It seems that the second one omits the zeros
>>>> Is this some weird gnu - non-gnu diffence? something I missed in the 
>>>> documentation.
>>>> Any suggestions what to do aboout that?
>>>
>>>
>>
>>
>> Get a non-broken implementation.  If this is not an option, use %2s
>> instead and convert the strings to double with (val[0] - '0') * 10.0 + 
>> val[1] - '0'.
>>
>> If needed, you can also check the validity of the strings with 
>> isdigit((unsigned char)val[0]) && isdigit((unsigned char)val[1])
>>
>> Dan
>> -- 
>> Dan Pop
>> DESY Zeuthen, RZ group
>> Email: Dan.Pop@ifh.de
>>
>>
>>
> 
> 

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: sscanf.patch
URL: <http://sourceware.org/pipermail/newlib/attachments/20030320/e8a91909/attachment.ksh>


More information about the Newlib mailing list